所以,我有这个循环:
int counter1 = 0;
ifstream incard;
string card;
string cardname;
stringstream out;
while (counter1 < 4) {
counter1 = counter1 + 1;
out << counter1;
out << ".card";
card = out.str();
cout << card;
system("PAUSE");
incard.open(card.c_str());
incard >> cardname;
cout << cardname << endl;
incard.close();
out.str("");
}
1.card包含文字“天使”
2.card包含文字“Devil”
3.card包含文字“Firaxis”
4.card包含文字“罗伯特”
这是我得到的输出:
1.cardPress any key to continue . . .
Angel
2.cardPress any key to continue . . .
Devil
3.cardPress any key to continue . . .
Devil
4.cardPress any key to continue . . .
Devil
谁能帮我弄清楚我做错了什么,为什么它没有读取超过 2.card 的任何一个卡文件?