首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

为什么是这样解决方法

2012-04-28 
为什么是这样#includeiostream#includestringusing namespace stdint main(){int secondpos,thirdpos

为什么是这样
#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就够了。不过如一楼所说,程序会有问题

热点排行