C++,如何把一个文本里的单词一个个存入数组结构?

文本是这样的:
when i wake up the other side of the bed is cold my
fingers stretch out seeking prims warmth but finding
only the rough canvas cover of the mattress she
must have had bad dreams and climbed in with our
mother of course she did this is the day of the
reaping
i prop myself up on one elbow theres enough light in

怎么实现这个: arry[0].word = when array[1].word = I array[2].word=wake
我试着用了getline: while(getline(ifs,useless,' ')
但是这样的话会把很多空格,换行一起录入进去,有没有办法只单单录入单词?

可以用string,遇到空格会自动换下一个。
#include<iostream>
int n;
string s[1001];
int main(){
freopen("text.in","r",stdin);
for (int i=1; i<=n; i++) cin>>s[i];
return 0;
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网