BUFF 在C++ 中取其中一部分 并且写到固定的目录下
2015-06-08 16:14
260 查看
#include <iostream>
#include <string>
using namespace std;
int main()
{
char *p = "D:\\Work\\s\\s.jpg";
string temp = p;
int pos = temp.find_last_of('\\');
string s(temp.substr(pos + 1) );
system("pause");
return 0;
}
从上面提取出来的s 是18082.jpg 比如,那么如果我们想这个图片写到D:\\images\\目录下面。好像在matlab 中是这样执行的:
imwrite(strcat("d:\\images\\",s),image);
在c++ 这样写报错,因为s 是string 类型的。
如果需要写,那么我们可以 使用下面的方法:
提取出来18082.jpg 从一个路径下。写到我们想写的路径下:
string ImageName = buff;
int pos = ImageName.find_last_of('\\');
string s(ImageName.substr(pos + 1) );
const char *p = s.data();
char ptemp[30];
sprintf(ptemp,"d:\\images\\%s",p);
imwrite(ptemp,image2);
特别指出:
sprintf(ptemp,"d:\\images\\%s",p); 这句话的作用相当于strcat("d:\\images\\",s)
#include <string>
using namespace std;
int main()
{
char *p = "D:\\Work\\s\\s.jpg";
string temp = p;
int pos = temp.find_last_of('\\');
string s(temp.substr(pos + 1) );
system("pause");
return 0;
}
从上面提取出来的s 是18082.jpg 比如,那么如果我们想这个图片写到D:\\images\\目录下面。好像在matlab 中是这样执行的:
imwrite(strcat("d:\\images\\",s),image);
在c++ 这样写报错,因为s 是string 类型的。
如果需要写,那么我们可以 使用下面的方法:
提取出来18082.jpg 从一个路径下。写到我们想写的路径下:
string ImageName = buff;
int pos = ImageName.find_last_of('\\');
string s(ImageName.substr(pos + 1) );
const char *p = s.data();
char ptemp[30];
sprintf(ptemp,"d:\\images\\%s",p);
imwrite(ptemp,image2);
特别指出:
sprintf(ptemp,"d:\\images\\%s",p); 这句话的作用相当于strcat("d:\\images\\",s)
相关文章推荐
- C++ 中 五种基本的内存分配方式
- C++ static 静态成员变量 和 静态成员函数
- C++程序设计 - Week 6 多态与虚函数
- 第十四周项目4(3)-处理C++源代码的程序
- c++ --> static关键字总结
- 第十四周项目4(2)-处理C++源代码的程序
- C++64位整型相乘取模的溢出处理(一)
- C++经典面试题
- C++全局变量的声明和定义
- 第十四周项目4(1)-处理C++源代码的程序
- 模板类和友元函数
- 下推栈实现(c++编程思想 p136)
- 【Minimum Window】cpp
- 关于C#中调用C++编写的DLL(非托管的DLL)的实现和问题记录
- C++ ofstream和ifstream详细用法
- 用c++写的数字阅读软件!
- VC++ 里面的_tmain 和 main的区别
- C++ this 指针 浅析
- C++9.5 vector/list/queue容器的区别与选用
- 一个同学的c++的故事(推测c++的由来)(一)