我有一個C++代碼,可以從目錄中讀取多個txt文件。但是這些文件是指定的格式,即abc01.txt,abc02.txt,abc03.txt .....,abc99.txt。如何以指定的格式讀取C++中的多個txt文件。
我可以讀取格式爲abc1.txt,abc2.txt,abc3.txt .....,abc99.txt的文件。使用我的代碼。問題是我不能讀取整數值01至09.
請幫我我如何編輯我的代碼並閱讀所有文件。
我的代碼:
for(files=1;files<=counter;files++)
{ stringstream out;
out<<files;
infile="./input/abc"+out.str()+".txt";
input.open(infile.c_str());
}
殘酷而簡單。可以避免使用std :: to_string的字符串流。 – user4581301