#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <cstdio>
using namespace std;
istream &read(istream &);
int main(int argc,char *argv[]) //argv是一个无参数的指针数组或者char*字符串
{
string str2;
read(cin);
cout << "Enter a string:" << endl;
cin >> str2;
cout << str2 << endl;
cout << "part2:" << endl;
cout << "begin to print file's text:" << endl;
ifstream in(argv[1]);
read(in);
return 0;
}
istream &read(istream & is)
{
string str;
while(getline(is,str))
{
cout << str << endl;
}
is.clear(); //最后is接受的是EOF,所以流的eofbit会被置位,必须要复位才可以后续使用
return is;
}
c++ primer 5th p289页练习题自己的解答程序
猜你喜欢
转载自blog.csdn.net/digitalkee/article/details/108899575
今日推荐
周排行