📄 streaminherit.cpp
字号:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#include "prompt.h"
// show stream inheritance
void doInput(istream& input)
// precondition: there are three strings to read in input
{
string s;
int k;
for(k=0; k < 3; k++)
{ input >> s;
cout << k << ".\t" << s << endl;
}
cout << endl;
}
int main()
{
string filename = PromptString("filename: ");
ifstream input(filename.c_str());
string firstline;
getline(input,firstline); // first line of input file
istringstream linestream(firstline); // stream bound to first line
cout << "first three words on first line are\n-----" << endl;
doInput(linestream);
cout << "first three words on second line are\n---" << endl;
doInput(input);
cout << "first three words from keyboard are\n---" << endl;
doInput(cin);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -