hyp*_*not 7 c++ string visual-studio-2010 command-line-arguments
我正在阅读C++ Primer一书,它在文件输入输出章节中使用:
ifstream infile(ifile.c_str());
Run Code Online (Sandbox Code Playgroud)
打开名称在字符串中的文件ifile.
我尝试了代码,即使没有也能完美运行c_str().那么使用它有什么意义呢?
c_str()当我尝试从命令行参数打开文件时,我应该使用吗?我的意思是哪个是正确的用法:
ifstream fin( argv[1] )
Run Code Online (Sandbox Code Playgroud)
要么
ifstream fin( argv[1].c_str() )
Run Code Online (Sandbox Code Playgroud)
那本书相当陈旧(至少,我的版本相当陈旧,也许你的版本也是你的.)iostream图书馆比STL和string班级年龄大得多; 早期的vrsions iostream没有string构造函数,就是这样.
| 归档时间: |
|
| 查看次数: |
13308 次 |
| 最近记录: |