我输入 aswef然后Ctrl+Z就成了 asweffe^Z接着第二个 aswe^Z,然后程序没有反应.
程序是用来判断一个string对象是否是另一个string对象的起始部分。比如awse 是awsewdf的起始部分,那么返回true.
请帮看一下程序,谢谢各位了。
#include <iostream>
#include <cstdlib>
#include <string>
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main()
{
string s1,s2;
bool t=true;
while (cin>>s1)
{}
while (cin>>s2)
{}
if (s1.size()<=s2.size())
{
for (string::size_type iv=0; iv!=s1.size(); ++iv)
{
if (s1[iv]!= s2[iv])
{
t=false;
break;
}
}
}
else
{
for (string::size_type iv=0; iv!=s2.size(); ++iv)
{
if (s1[iv]!= s2[iv])
{t=false;
break;
}
}
}
if (t)cout<<"true!"<<endl;
else
cout<<"false!"<<endl;
system("pause");
return 0;
}