要打开文件的字符串变量

string variable to open file

本文关键字:字符串 变量 文件      更新时间:2023-10-16

我的代码应该打开100个文件(并对它们进行处理),下一个索引的路径如下:"c:\Naprzeme\NAPRZ100.IN"下一个是"c:\Naphzeme\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
}

CCD_ 1返回错误

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

fstream infile(supremeCounter.c_str());