C++----练习--string 从文件中一个一个单词的读直到文件尾

从文件中读取单词、并每行显示一个:

1、

#include<iostream>
#include<string>
#include<vector>


int main()
{
    std::string str="";
    while(std::cin>>str)
    {
        std::cout<<str<<std::endl;    
    }
    return 0;


}

2、调用

[root@workstudio tmp]# g++ -o main main.cpp 
[root@workstudio tmp]# ./main <./input.txt 
123456789
abcdefg

 

posted on 2016-08-22 09:54  蒋乐兴的技术随笔  阅读(2049)  评论(0编辑  收藏  举报

导航