一般串输入一个句子单词数是动态的怎么获得这些单词呢?
下面是一种方法:
#include <iostream.h>
void main()
{
char stri[80];
while (cin>>stri) //循环读入一个句子的单词
cout<<"word read is:"<<stri<<'/n';
}
如:输入 how are you
输出结果为
word read is:how
word read is:are
word read is you
本文介绍了一种通过C++程序从连续输入的字符串中提取单词的方法,并提供了完整的代码示例。该方法能够逐个读取并输出每个单词。
一般串输入一个句子单词数是动态的怎么获得这些单词呢?
下面是一种方法:
#include <iostream.h>
void main()
{
char stri[80];
while (cin>>stri) //循环读入一个句子的单词
cout<<"word read is:"<<stri<<'/n';
}
如:输入 how are you
输出结果为
word read is:how
word read is:are
word read is you
1127
1621

被折叠的 条评论
为什么被折叠?