c++ 对数组赋值和判断

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:45:08
cout << "type some words, (stop to stop)"<< endl;
cin >> word;
for (n=0; strcmp (word[], "stop"); n++)
{
cin >> word[n];
}

cout << word << endl;

希望可以实现的是当用户输入到stop的字符时候,程序自动停止,然后输出所有刚刚输入的字符,好像我在判断那里有问题,不知道该怎么修改,望高手帮忙谢谢!

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
vector<string> svec;
string word;
cout << "type some words, (stop to stop)"<< endl;
while(cin>>word && word!="stop")
{
svec.push_back(word);
}
for(vector<string>::size_type ix=0;ix!=svec.size();++ix)
{
if(ix%10==0 && ix!=0)
cout<<endl;
cout<<svec[ix]<<" ";
}
return 0;
}

/*
type some words, (stop to stop)
I am a student, I am from shang hai university,
my hobby is reading, and I like make friends with
everyone, and so on.
stop
I am a student, I am from shang hai university,
my hobby is reading, and I like make friends with
everyone, and so on.
*/

int main()
{
std::vector<std::string> vct;