文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>从句子中读出以空格分隔的单词

从句子中读出以空格分隔的单词

时间:2010-08-16  来源:idx001

记一下:
C++ Primer P318
ifstream input;
string line;
getline(input,line)
istringstream stream(line);//这里即一次读入一个单词
使用istringstream记得头文件sstream否则有以下错误:
`std::istringstream stream' has initializer but incomplete type



string first,last=string("hello word");
istringstream stream(last);
stream>>first;
cout<<first<<endl;//输出hello


从文件中读出亦是一样,可用ifstream流:
    const string file="ftest.txt";
    string word;
    ifstream in;
    in.close();
    in.clear();
    in.open(file.c_str());
    while(in>>word){
                    cout<<word<<endl;
    }//while 亦是遇到空格读一次,直至文件结束
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载