读书人

为什么是这样解决方法

发布时间: 2012-04-28 11:49:53 作者: rapoo

为什么是这样
#include<iostream>
#include<string>
using namespace std;

int main()
{
int secondpos,thirdpos;
string sentence,str;
const string str1="and";

cout<<"input the sentence: ";
getline(cin,sentence);
str=sentence.substr(sentence.find(str1)+3,1000);
secondpos=str.find(str1)+sentence.find(str1)+3;
cout<<"the second position of \"and\" is "<<secondpos<<endl;

str=sentence.substr(secondpos+3,1000);
thirdpos=secondpos+str.find(str1)+3;
cout<<"the third position of \"and\" is "<<thirdpos<<endl;
return 0;
}
为什么这段代码要按两次Enter键才出来结果?

[解决办法]
一下Enter就够了。不过如一楼所说,程序会有问题

读书人网 >C++

热点推荐