C++中open() 函数不能传string的解决方法
来源:互联网 发布:淘宝开店开通不了 编辑:程序博客网 时间:2024/05/22 05:38
C++ 的open()只能传入const char * 类型的,当传入string类型的就会出错,对此C++中提供了c_str()的解决方法
例如:
ofstream out;
string filename;
filename = "C:\\Users\\Administrator\\0113\\01\\" + argv[1];
out.open(filename.c_str());
out << "hello world!" << endl;
out.close();
就可以在制定目录下生成 以argv[1]命名的文件了;
但是要对 filename.c_str();修改就只能用c的 strcpy()等函数了。
0 0
- C++中open() 函数不能传string的解决方法
- python中open函数在遇到中文路径的解决方法
- C语言中open函数
- C语言中open函数
- C语言中open函数
- C语言中open函数
- C语言中open函数
- 2、ubuntu中man不能查询函数的解决方法
- HMC不能open terminal windows的解决方法之一
- window.open()函数中,Name参数不能包括特殊字符
- window.open()函数中,Name参数不能包括特殊字符
- C中string比较函数
- file_get_contents函数不能使用的解决方法
- file_get_contents函数不能使用的解决方法
- MySQL函数不能创建的解决方法
- MySQL函数不能创建的解决方法
- file_get_contents函数不能使用的解决方法
- MySQL函数不能创建的解决方法
- 黑马程序员java基础之GUI
- objective-c 类
- Microsoft.Office.Interop.Excel的用法
- unity知识点小结
- android判断横竖屏
- C++中open() 函数不能传string的解决方法
- tomcat配置SSL
- 3d014乾坤神胆专家014期
- ClassXmlAplicationContext、FileSystemXmlApplicationContext
- touch 命令
- 利用正则表达式检查网址,手机号,邮箱是否正确(RegexKitLite)
- segementation fault (core dumped) in C
- 九枚硬币翻转问题
- DSOFramerControl简单使用