我是C++初學者,下面的程序很簡單,但我不知道爲什麼當輸入「EXIT」時,程序終止,但它應該打印出之前輸入的名字!break退出程序 - C++
下面的代碼:
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main()
{
set <string> myset;
set <string> :: const_iterator it;
it = myset.begin();
string In;
int i=1;
string exit("EXIT");
cout << "Enter EXIT to print names." << endl;
while(1)
{
cout << "Enter name " << i << ": " ;
cin >> In;
if(In == exit)
break;
myset.insert(In);
In.clear();
i++;
}
while(it != myset.end())
{
cout << *it << " " ;
it ++ ;
}
cout << endl;
}
在此先感謝。
感謝它工作:) – Nour