一.问题描述

键盘输入“I am a student./My university is STDU./I love my university.”

用流对象的成员函数get读取并打印到屏幕上;

分别用流对象的成员函数get函数和getline函数读取第一个“/”之前的字符串,之后观察当前指针所指内容,观察是否有差别,若有,请在实验报告中描述;

先读取第一个“/”前的字符串打印至屏幕,再读取第二个“/”后的字符串打印至屏幕。

二.设计思路

三.流程图

四.伪代码 

1

五.代码实现 

#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
	string s; int i = 0;
	getline(cin,s);
	char ch[1000];
	ofstream myfile1("text.txt");
	myfile1 << s;
	myfile1.close();
	ifstream myfile2("text.txt");
	while (myfile2.get(ch[i++])) {}
	myfile2.close();
	for (int i = 0; i < s.length(); i++) {
		cout << ch[i];
	}
	cout << endl << endl;
	int count =0;
	for (int i = 0; i < s.length(); i++) {
		if (ch[i] == '/') {
			cout << endl;
			i++;
			count++;
		}
		if (count == 2) break;
		cout << ch[i];
	}
	cout << endl ;
	
	
	return 0;
}

 

posted on 2023-05-14 23:24  leapss  阅读(15)  评论(0)    收藏  举报