【问题标题】:string variable to open file [duplicate]打开文件的字符串变量[重复]
【发布时间】:2013-02-06 11:45:04
【问题描述】:

我的代码应该打开 100 个文件(并对它们做一些事情),路径中的下一个索引如下: "c:\Naprzeme\NAPRZ100.IN" 下一个是 "c:\Naprzeme\NAPRZ101.IN" 等等:

for (int as=100;as<159;as++){
    ostringstream ss;
    ss << as;
    string cherk = ss.str();
string supremeCounter = "c:\\Naprzeme\\NAPRZ"+cherk+".IN";
fstream infile(supremeCounter);
//....other code here
}

fstream infile(supremeCounter) 返回错误

28 31 C:\Users\talent\Documents\File.cpp [Error] no matching
 function for call to     'std::basic_fstream<char>::basic_fstream(std::string&)' 
candidates are: //(here some libs)...

【问题讨论】:

    标签: c++ string file


    【解决方案1】:

    fstream infile(supremeCounter.c_str());

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多