我是C++初学者,下面的程序很简单,但是我不知道为什么当输入“EXIT”时,程序终止,虽然它应该打印出之前输入的名称!
这是代码:
#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;
}
提前致谢。