python人工智能学什么:帮忙改个c++小程序

来源:百度文库 编辑:高校问答 时间:2024/05/10 09:29:30
输入单词直到输入“done”结束。并显示单词数
#include <iostream>
#include <string>

int count=0;
string word;
string str="done";
int main()
{
using namespace std;
cout<<"Enter words (to stop,type the word done):";
do
{
cin<<word;
count++;
} while(word=str);
cout<<count<<endl;
cin.get();
应该是getline(cin,word);
但还是不行啊?

#include <iostream>
#include <string>

using namespace std;

int main()
{
int count=0;
string word;
string str="done";

cout << "Enter words (to stop,type the word done):";
cin >> word;
while(word!=str)
{
count++;
cin >> word;
}

cout << count << endl;

return 0;
}

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
int count = 0, index = 1;
string word, str = "done";

cout << "Enter words (to stop, type the word done) : " << endl;
do
{
cout << index << " : ";
getline(cin, word);
index++;
count++;
} while(word!=str);

cout << "Word(s) Count : " << count-1 << endl;
cin.get();

return 0;
}

把while(word=str)改为while(word==str)

前面答的挺好了

我来学习的
看下~~