我需要帮助。我想写的程序,打开文件在哪里是问题,并通过问题阅读问题,文件中的问题从<开始,并以>如何与类如何做? 我想程序去一个问题,然后你回答你后得到下一个问题。 现在我这样做: `C++逐行读取文件
int main() {
ifstream myfile;
myfile.open ("21fundamentalvariabletypes.txt");
while (myfile){
int i = 1;
string strInput;
getline(myfile, strInput);
if (strInput == "<") {
cout << i << ".";
i++;
}
if (strInput == ">") {
cout << endl;
}
else {
cout << strInput << endl;
i++;
}
}
return 0;
}
和我得到这个屏幕上:
1. < STA济ispravan nacin deklaracije promenljive? - a = 4; * int a; - int a = 4; - int a = 4
1. < Povezati ispravan par? - 1 AA - 2 BB - 3 CD - 4哒 * 1-> 3 * 2-> 3 * 3-> 4 * 4-> 1
为什么犯规我++工作,并为什么我第一次有1. <。但是,当我不把if (strInput == ">")
等,然后我有1,然后质疑
我们不打算写一个完整的程序给你。写下你的逻辑,并在这里提出任何技术问题。 – Ryan
你问了一个东西的教程,你可以很容易地在谷歌发现 –
看看'fopen','fgets','fclose'都在手册页#3 –