【无标题】5 自用历程

目录

一,

二.

初级

1. 元素逆置

2.冒泡排序

3helloworld!

4.7的游戏

5.99乘法表

6.结构体始

7.3个老师分别管理5个学生

8.对结构中根据年龄排序

9.简易版通讯录

初级+1 

10.堆区创建整型数组(new,delete)

11.运用类,求圆的周长

12.实现学生类,方法可以给学生信息赋值,方法可以显示学生信息

13.1.失败的深浅拷贝函数

13.2.修改 

14.返回对象本身用*this的实例

15.测试友元 

16.重载加法+

17.步入多态.始

17.1)多态实现计算器,仅仅加减法

17.2)多态实现零件组成成品(有点乱)

18.文件操作.始(很大欠缺)


一,

浪费了许多时间练习,真尴尬呀,小小要求都写不出来,这里就用来...新手一个.

二.

初级

1. 元素逆置

1.1

#include<iostream>
using namespace std;


void text() {
	int arr[7] = { 1,2,3,4,5,6 };
	int arr1[10] = {};
	for (int i = 0;i < sizeof(arr) / sizeof(arr[0])-1;i++) {
		//arr1[sizeof(arr) - i - 1] = arr[0];
		arr1[5 - i] = arr[i];
	}
	for (int i = 0;i < 6;i++) {
		cout << arr1[i]<<"\n";
	}
	cout << sizeof(arr)/sizeof(arr[0]);
}
int main() {
	text();
	system("pause");
	return 0;
}

结果:6543217

通过创建新的数组,将原数组开头放入目标数组尾部,依次加减对换

1.2

void text() {
	int arr[] = { 1,2,3,4,5,6 };
	int start = 0;
	int end = sizeof(arr) / sizeof(arr[0])-1;
	for (;start < end;start++,end--) {
		int tep = 0;
		tep = arr[start];
		arr[start] = arr[end];
		arr[end] = tep;
	}
	for (int i = 0;i < 6;i++) {
			cout << arr[i]<<"\n";
		}
}

结果654321

通过下标的方式,从数组开头结尾向中间两两对换

2.冒泡排序

2.1 

void text() {
	int arr[] = { 5,2,4,1,7,9,3 };
	int longs = sizeof(arr) / sizeof(arr[0]);
	for (int i = 0;i < longs;i++) {
		for (int j = i;j < longs;j++) {
			if (arr[i] > arr[j]) {
				int tep = 0;
				tep = arr[i];arr[i] = arr[j];arr[j] = tep;
			}
		}
	}
	for (int i = 0;i < sizeof(arr) / sizeof(arr[0]);i++) {
				cout << arr[i]<<"\n";
			}
}

 结果1234579

通过外循环对数组进行依次取数,内循环进行与该数后面的数进行比较,将较小的放入开头

3helloworld!

#include<iostream>
using namespace std;
#include<string>

int main() {
	cout << "hello world!" << endl;
	system("pause");
	return 0;
}

一切的开始了,加油 

4.7的游戏

1-100含7,7的倍数打印敲桌子

void text() {
	for (int i = 1;i <= 100;i++) {
		if (i % 10 == 7 || i / 10 == 7 || i % 7 == 0) {
			cout << "敲桌子" << endl;
		}
		else
		{
			cout << i << endl;
		}
	}
}

 结果便是1-100中含7和7的倍数的数字都用敲桌子进行替换

%10得到的是个位数为7、/10得到的是十位数为7、%7求的是7的倍数的数字

5.99乘法表

void text() {
	for (int i = 1;i <= 9;i++) {
		for (int j = 1;j <= i;j++) {
			cout << j << "*" << i << "=" << i * j<<"\t";
		}
		cout << endl;
	}
}

两个循环求乘法表 

6.结构体始

6.1

void text() {
	struct Student {
		string name;
		int age;
		int score;
	}stu2;//1

	struct Student stu1;//2
	stu1.age = 18;
	stu1.score = 99;
	stu1.name = "张三";

	cout << stu1.name<<"\t" << stu1.age << "岁\t" << "语文成绩:"<<stu1.score <<"分\t"<< endl;
	stu2.name = "李四";
	cout << "有一个同学叫做" << stu2.name << endl;
}

用了两种创建方式,通过结构体创建了张三、李四两个实体变量

 6.2

	struct Teacher {
		string name;
		struct Student arr[50];
	};

	Teacher tea1 = { "李老师"};
	tea1.arr[0] = { "赵六",19,99 };
	cout << tea1.arr->age << endl;

主要表现为结构体成员可以是结构体 

7.3个老师分别管理5个学生

#include<iostream>
using namespace std;
#include<string>
#include<ctime>

void text() {
	srand((unsigned int)time(NULL));//随机数
	struct Student {
		string name;
		int age;
		int score;
	};

	struct Teacher{
		string name;
		struct Student Sarr[5];
	};

	struct Teacher Tarr[3];

	string minzi = "ABCDE";
	for (int i = 0;i < 3;i++) {
		string ls = "teacher_";
		Tarr[i].name = ls + minzi[i];
		for (int j = 0;j < 5;j++) {
			string tx = "student_";
			Tarr[i].Sarr[j].name = tx + minzi[j];
			int random = rand() % 61 + 40;//随机数编成绩
			Tarr[i].Sarr[j].age = 19;
			Tarr[i].Sarr[j].score = random;
		}
	}
	for (int i = 0;i < 3;i++) {
		cout << Tarr[i].name << "\t" << "\t" << "\t" << "年龄\t" << "\t" << "成绩\t " << endl;
		for (int j = 0;j < 5;j++) {
			cout << "\t" << Tarr[i].Sarr[j].name <<"\t"
				<< "\t" << Tarr[i].Sarr[j].age << "\t"
				<< "\t" << Tarr[i].Sarr[j].score << endl;
		}
	}
int main() {

	text();
	system("pause");
	return 0;
}

 定义学生、老师两个结构体,一个老师结构体数组。

运用随机数对学生成绩进行赋值

运用字符串对老师、学生进行快速命名

8.对结构中根据年龄排序

#include<iostream>
using namespace std;
#include<string>

struct Yinxiong {
	string name;
	int age;
	string sex;
};
void paixu(struct Yinxiong Ya[], int len) {
	for (int i = 0;i < len;i++) {
		for (int j = 0;j < len - i-1;j++) {
			if (Ya[j].age > Ya[j + 1].age) {
				struct Yinxiong tem;
				tem = Ya[j];
				Ya[j] = Ya[j + 1];
				Ya[j + 1] = tem;
			}
		}
	}
}

void text() {
	struct Yinxiong Yarr[5] = {
		{"张三",19,"男"},
		{"bb",22,"男"},
		{"cb",18,"女"},
		{"db",17,"女"},
		{"eb",27,"男"},
	};
	int len = sizeof(Yarr) / sizeof(Yarr[0]);
	for (int i = 0;i < len;i++) {
		cout << Yarr[i].name << "\t" << Yarr[i].age << "\t" << Yarr[i].sex << endl;
	}
	cout << endl;
	paixu(Yarr, len);
	for (int i = 0;i < len;i++) {
		cout << Yarr[i].name << "\t" << Yarr[i].age << "\t" << Yarr[i].sex << endl;
	}
}

int main() {
	text();
	system("pause");
	return 0;
}

记录:

整体写的比较繁琐

对于struct Yinxiong 的结构体定义需要弄成全局变量 方便其他函数在定义与传参数时,前后能够相匹配。

9.简易版通讯录

22/05/29

#include<iostream>
using namespace std;
#include<string>
#define MAX 100

void showmeau() {//显示目录函数
	cout << "\t欢迎使用通讯录" << endl;
	cout << "\t\t请选择0-4" << endl;
	cout << "\t1.添加人员" << endl;
	cout << "\t2.显示人员" << endl;
	cout << "\t3.查找人员" << endl;
	cout << "\t4.删除人员" << endl;
	cout << "\t0.退出" << endl;
}

void exitTuichu() {//退出通讯录函数
	cout << "谢谢您的使用,成功退出" << endl;
	return;
}

//定义人的结构
struct Person {
	string name;
	string eleDianhua;
};

struct Person personarr[MAX];//定义通讯录结构

int sizerenshu = 0;//记录存入的人数

void tianJiarenyuan() {//添加人员函数
	if (sizerenshu <= MAX) {
		string name1;
		string eleDIanhua1;
		Person per1;
		cout << "请输入人的名字" << endl;
		cin >> name1;
		cout << "请输入人的电话" << endl;
		cin >> eleDIanhua1;
		per1.name = name1;
		per1.eleDianhua = eleDIanhua1;
		//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
		personarr[sizerenshu] = per1;
		sizerenshu++;
		cout << "添加成功" << endl;
	}
	else
	{
		cout << "人数已满,请做删减操作再添加" << endl;
		return;
	}
	cout << endl;
}

void showPer() {//显示通讯录所有人函数
	if (sizerenshu>0)
	{
		for (int i = 0;i < sizerenshu;i++) {
			cout << "姓名\t" << personarr[i].name << "\t电话\t" << personarr[i].eleDianhua << endl;
		}
	}
	else {
		cout << "当前通讯录为空" << endl;
	}
}

void Cazaoren() {//查找人函数,根据姓名查找
	if (sizerenshu > 0) {
		string name2;
		cout << "请输入您要查找的人的名字" << endl;
		cin >> name2;
		for (int i = 0;i < sizerenshu;i++) {
			if (personarr[i].name == name2) {
				cout << "查找成功" << endl;
				cout << "姓名\t" << personarr[i].name << "\t电话\t" << personarr[i].eleDianhua << endl;
			}
			else {
				cout << "查找失败" << endl;
			}
		}
	}
	else {
		cout << "当前通讯录为空" << endl;
	}
}

void Sancu() {//人员删除函数
	if (sizerenshu > 0) {
		for (int i = 0;i < sizerenshu;i++) {
			personarr[i] = {};
			cout << "删除成功" << endl;
			sizerenshu--;
		}
	}
	else {
		cout << "当前通讯录为空" << endl;
	}
}

//测试函数
void text() {
	while (true) {
		showmeau();
		int xuanZhe = 0;
		int xuanze = 0;
		cin >> xuanze;
		xuanZhe = (int)xuanze;
		cout << xuanze << endl;
		cout << xuanZhe << endl;
		switch (xuanZhe) {
		case 1://1.添加人员
			tianJiarenyuan();
			system("pause");
			system("cls");
			break;
		case 2://2.显示人员
			showPer();
			system("pause");
			system("cls");
			break;
		case 3://3.查找人员
			Cazaoren();
			system("pause");
			system("cls");
			break;
		case 4://4.删除人员
			Sancu();
			system("pause");
			system("cls");
			break;
		case 0://0.退出
			exitTuichu();
			system("pause");
			system("cls");
			return;
		}
	}
	
}
//主函数
int main() {
	text();
	//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
	//cout << sizerenshu << endl;
	system("pause");
}

//.通讯录
//1.添加人员
//2.显示人员
//3.查找人员
//4.删除人员
//0.退出

 目的:

  • 总结运用,
  • 通讯录的实现比较简单
  • switch语句对功能选择的选择,
  • while语句对功能重复操作做的循环,
  • for语句对通讯录数组成员遍历、添加、显示等功能的循环
  • 功能函数分开写
  • if语句对通讯录是否为空的判断

过程:

  • 功能选项显示函数---实现退出函数---定义人员结构、结构数组---定义全局变量sizerenshu---其他功能函数

分析

  • ①具有添加,显示,查找,删除等功能。未做修改的功能。将功能分开写在不同的函数当中,可以实现功能的具体化,应该是面向过程了。
  • ②运用循环加清屏的操作能对界面实现的更加简洁,
  • ③运用return直接退出函数,可以退出循环一直为真的结果
  • ④运用sizerenshu的全局变量对数组中存放的成员进行合理统计,方便和丰富了其他功能 

目前已知问题:

  • ①未对输入的姓名,电话是否合法判断
  • ②未实现拨号,查看拨号等功能
     

初级+1 

10.堆区创建整型数组(new,delete)

0530

#include<iostream>
using namespace std;

void text() {
	int* arr = new int[10];//创建10整型数据的数组

	for (int i = 0;i < 10;i++) {
		arr[i] = i;
	}
	for (int j = 0;j < 10;j++) {
		cout << arr[j]  ;
	}
	cout << endl;
	delete[] arr;//释放堆区数组
}

int main() {
	text();
	system("pause");
}

熟悉 new和delete关键字,一创建一释放delete关键字对数据的释放注意区分是数组还是简单变量

11.运用类,求圆的周长

0530

//int c = 10;
class yuan1 {//定义圆类
public:
	int banJin;//类内属性
	double qiuZoucCan() {//类内方法
		return 2 * PI * banJin;
	}
	//int abc() {
	//	return c;
	//}
};

void text001() {
	yuan1 y1;
	y1.banJin = 10;
	cout<<"半径为"<<y1.banJin<<"的圆的周长为"<< y1.qiuZoucCan()<<endl;
}

熟悉类的定义,类的方法调用

实例类的类内方法可以调用实例本身类的成员属性,亦可以调用全局变量等

12.实现学生类,方法可以给学生信息赋值,方法可以显示学生信息

0530

class student {
public:
	string m_name;
	int m_age;

	void setstu(string name,int age) {
		m_name = name;
		m_age = age;
	}
	
	void showstu() {
		cout << "姓名:" << m_name << "\t年龄:" << m_age << endl;
	}
};
void text() {
	student st1;
	st1.setstu("张三",18);
	st1.showstu();
}

13.1.失败的深浅拷贝函数

0530

class person {
public:
	person(){
		cout << "无参构造" << endl;
		mage = 0;
		mhhhe = 0;
	}
	person(int age, int hhhe) {
		cout << "有参构造" << endl;
		mage = age;
		mhhhe = hhhe;
		//int *mhhhe = new int(hhhe);
	}
	person(const person& p) {
		cout << "拷贝构造" << endl;
		mage = p.mage;
		mhhhe =  /*new*/ int(p.mhhhe);
	}
	~person() {
		cout << "析构函数" << endl;
	}
public:
	int mage;
	int mhhhe;

};


void text() {
	person p1(10,20);
	person p2(p1);
	cout << p1.mage << endl;
	cout << p1.mhhhe << endl;
	//cout << p1.mhhhe << endl;
	cout << p2.mage << endl;
	cout << p2.mhhhe << endl;
	//cout << p2.mhhhe << endl;
}

需要用到new,但是使用的话就会出问题

待更深理解再回复

13.2.修改 

0530

class person {
public:
	person(){
		cout << "无参构造" << endl;
		mage = 0;
		mhhhe = 0;
	}
	person(int age, int hhhe) {
		cout << "有参构造" << endl;
		mage = age;
		mhhhe = new int(hhhe);
	}
	person(const person& p) {
		cout << "拷贝构造" << endl;
		mage = p.mage;
		//mhhhe = p.mhhhe;//浅拷贝,默认拷贝
		mhhhe =  new int(*p.mhhhe);//深拷贝,重构拷贝
	}
	~person() {
		if (mhhhe != NULL) {
			delete mhhhe;
			mhhhe = NULL;
		}
		cout << "析构函数" << endl;
	}
public:
	int mage;
	int *mhhhe;

};


void text() {
	person p1(10,20);
	cout << p1.mage << endl;
	cout << *p1.mhhhe << endl;
	person p2(p1);
	cout << p2.mage << endl;
	cout << *p2.mhhhe << endl;
}

发生13.1及之后的问题的原因有:

  • ①类内hhhe为int类型并非指针的类型
  • ②对于自己开辟的空间需要自己在析构函数中自己释放,
  • ③,②的发现是在解决第一个问题后,又发现不重构拷贝函数,仍然没有发生重复释放的问题

14.返回对象本身用*this的实例

0530

#include<iostream>
using namespace std;

class person {
public:
	person() {

	}
	person(int a) {
		jiashu = a;
	}
	int jiashu;

	//person  addshu(person &p) {//结果为10和20//这两个&&我理解为可以调用本身的这个函数
	//	this->jiashu = this->jiashu + p.jiashu;
	//	//return *this;
	//	return jiashu;
	//}
	person& addshu(person& p) {//结果为10和30
		this->jiashu = this->jiashu + p.jiashu;
		//return *this;
		return *this;
	}
};

void text() {
	person p1;
	person p2(10);
	p1.jiashu = 10;
	p2.addshu(p1).addshu(p1);
	cout << p1.jiashu << endl;
	cout << p2.jiashu << endl;
}
int main() {
	text();
	system("pause");
	return 0;
}

  当不是 p2.addshu(p1).addshu(p1);而仅仅只是调用一次addshu()函数时,该函数返回类型可以为int,同时返回return *this;改为return this->jiashu;

15.测试友元 

 0531

//定义一个具有公共、私有的建筑类
class buid {
	friend void goodfri(buid& bu);
	//friend void buid2::fri1(buid& bu);//定义没有意义
	friend class buid2;
public:
	buid() {//构造函数
		roomsit1 = "keting ";
		sitroom2 = "woshi";
	}
public:
	string roomsit1;
private:
	string sitroom2;//私有变量

};

//为朋友的类外函数
void goodfri(buid& bu) {
	cout << bu.roomsit1 << endl;
	cout << bu.sitroom2 << endl;
}

//不是朋友的类外函数
void badfri(buid& bu) {
	cout << bu.roomsit1 << endl;
	//cout << bu.sitroom2 << endl;//报错,不可访问
}

//为朋友的类
class buid2 {
public:
	void fri1(buid& bu) {
		cout << bu.roomsit1 << endl;
		cout << bu.sitroom2 << endl;
	}
};

//不是朋友的类
class buid3 {
public:
	void fri1(buid& bu) {
		cout << bu.roomsit1 << endl;
		//cout << bu.sitroom2 << endl;//报错,不可访问
	}
};

//测试
void text() {
	buid bu1;
	goodfri(bu1);
	badfri(bu1);
	buid2 buu1;
	buu1.fri1(bu1);

}

对于friend关键字修饰的类外函数,别的类,可以访问本身类的私有成员变量

class A {
	friend class B;
public:
	A() {
		cout << "A  的构造函数" << endl;
		age = 10;
		bge = 20;
		cge = 30;
	}
	~A() {
		cout << "A  的析构函数" << endl;
	}
public:
	int age;
protected:
	int bge;
private:
	int cge;
};

class B {
public:
	B() {
		cout << "B  的构造函数" << endl;
		a1 = new A;
	}
	~B() {
		cout << "B  的析构函数" << endl;
		if (a1 != NULL) {
			delete a1;
			a1 = NULL;
		}
	}
	void visit() {
		cout << a1->age << endl;
		cout << a1->bge << endl;
	}
private:
	A* a1;
};

void text() {
	B b1;
	b1.visit();
}

16.重载加法+

//例 加法
class jia1 {
public:
	int a ;
	//通过成员函数重载
	jia1 operator+ (jia1 jiaa) {//对应j5
		jia1 temp;
		temp.a = jiaa.a + this->a;
		return temp;
	}
};

jia1 jiafacongzai(jia1 jiaa, jia1 jiaaa) {//以函数方式,对应j4
	jia1 temp;
	temp.a = jiaa.a + jiaaa.a;
	return temp;
}
//通过全局函数重载
//jia1 operator+(jia1 jiaa, jia1 jiaaa) {//关键字operator可简化函数名不写,对应j5
//	jia1 temp;
//	temp.a = jiaa.a + jiaaa.a;
//	return temp;
//}

void jia() {
	jia1 j1;
	j1.a = 10;
	jia1 j2;
	j2.a = 20;
	jia1 j3;
	j3.a = j1.a + j2.a;//普通加法
	cout << j3.a << endl;
	jia1 j4;
	j4 = jiafacongzai(j1, j2);
	cout << j4.a << endl;
	jia1 j5 = j1 + j2;
}

主要面对的是自定义类型的时候使用

17.步入多态.始

class Animal {
public:
	virtual void move() {
		cout << "动物在走" << endl;
	}
};

class cat :public Animal {
public:
	void move() {
		cout << "猫在走猫步" << endl;
	}
};

class big :public Animal {
public:
	void move() {
		cout << "猪在跳舞" << endl;
	}
};

void moveaaa(Animal& animal) {
	animal.move();
}

void text() {
	cout << "zhixin " << endl;

	cat cat1;
	moveaaa(cat1);

	big big1;
	moveaaa(big1);
}

当我们传入为猫的时候,结果就是猫的类的函数在执行

缺少virtual的时候,结果都为“动物在走”

17.1)多态实现计算器,仅仅加减法

class YuanSuanYuanLei {
public:
	YuanSuanYuanLei() {
		a = 0;
		b = 0;
	}
	virtual int gett() {
		return 12;
	}
	int a;
	int b;
};

class jiaafa :public YuanSuanYuanLei {
public:
	int gett() {
		return a + b;
	}
};
class jiannfa :public YuanSuanYuanLei {
public:
	int gett() {
		return a - b;
	}
};

void text() {
	//父类指针指向子类对象
	YuanSuanYuanLei* abs1 = new jiaafa;
	abs1->a = 100;
	abs1->b = 23;
	cout << abs1->gett() << endl;
	delete abs1;

	YuanSuanYuanLei* abs2 = new jiannfa;
	abs2->a = 100;
	abs2->b = 23;
	cout << abs2->gett() << endl;
	delete abs2;
}

17.2)多态实现零件组成成品(有点乱)

//c公司,d公司
//A零件,B零件==可以组成e成品
//抽象AB零件,成品

class A {
public:
	virtual void Asencen() = 0;
	string minzi;
};
class B {
public:
	virtual void Bsencen() = 0;
	string minzi;
};

//class CenPinShiYong {
// 该部分多余,为成品生成的抽象,
// 可是下边并不需要,因为只有一种生成方式
//public:
//	virtual ~CenPinShiYong() = 0;
//	virtual void CenPin() = 0;
//};
//CenPinShiYong::~CenPinShiYong() {
//
//}

class cgsiA :public A {//c公司生产a
public: 
	cgsiA() {
		minzi = "c公司";
	}
	void Asencen() {
		cout << "c公司生产a" << endl;
	}
	string minzi;
};
class cgsiB :public B {//c公司生产B
public:
	cgsiB() {
		minzi = "c公司";
	}
	void Bsencen() {
		cout << "c公司生产B" << endl;
	}
	string minzi;
};
class dgsiA :public A {//d公司生产a
public:
	dgsiA() {
		minzi = "d公司";
	}
	void Bsencen() {
		cout << "d公司生产a" << endl;
	}
	string minzi;
};
class dgsiB :public B {//d公司生产B
public:
	dgsiB() {
		minzi = "d公司";
	}
	void Bsencen() {
		cout << "d公司生产B" << endl;
	}
	string minzi;
};
//class CaiSiCenPin :public CenPinShiYong {//cai为kai
// 该部分多余
//public:
//	CaiSiCenPin(A* a1, B* b1) {
//		ma = a1;
//		mb = b1;
//	}
//	void CenPin() {
//		cout << "生成中" << endl;
//		ma->Asencen();
//		mb->Bsencen();
//		cout << ma->minzi<<"和"<<mb->minzi << "的生成e成品生成成功" << endl;
//	}
//	~CaiSiCenPin()
//	{
//		if (ma != NULL) {
//			delete ma;
//			ma = NULL;
//		}
//		if (mb != NULL) {
//			delete mb;
//			mb = NULL;
//		}
//	}
//	A* ma;
//	B* mb;
//};
class CaiSiCenPin {//cai为kai
public:
	CaiSiCenPin(A* a1, B* b1) {
		ma = a1;
		mb = b1;
	}
	void CenPin() {
		cout << "生成中" << endl;
		ma->Asencen();
		mb->Bsencen();
		cout<< "e成品生成成功" << endl;
	}
	~CaiSiCenPin()
	{
		if (ma != NULL) {
			delete ma;
			ma = NULL;
		}
		if (mb != NULL) {
			delete mb;
			mb = NULL;
		}
	}
private:
	A* ma;
	B* mb;
};

void text() {
	cout << "第一件成品" << endl;
	CaiSiCenPin* abs1 = new CaiSiCenPin(new cgsiA, new cgsiB);
	abs1->CenPin();
	delete abs1;
	cout << endl;
	cout << "第二件成品" << endl;
	CaiSiCenPin* abs2 = new CaiSiCenPin(new cgsiA, new dgsiB);
	abs2->CenPin();
	delete abs2;
}

18.文件操作.始(很大欠缺)

void text() {
	//ofstream ofs;
	//ofs.open("新建文本文档.txt", ios::out);
	system("pause");
	//ofs << "我很帅,rui";
	//ofs.close();

	ifstream ifs;
	ifs.open("新建文本文档.txt", ios::in);
	if (!ifs.is_open())
	{
		cout << "文本打开失败" << endl;
		return;
	}
	//①
	char buf[1024] = { 0 };
	while (ifs >> buf) {
		cout << buf << endl;
	}
	//②
	//char buf[1024] = { 0 };
	//while (ifs .getline(buf,sizeof(buf))) {
	//	cout << buf << endl;
	//}

	//③
	//string buf;
	//while (getline(ifs,buf)) {
	//	cout << buf << endl;
	//}
	//④好像读不到中文
	//char c;
	//while ((c=ifs.get())!=EOF) {
	//	cout << c << endl;
	//}
	ifs.close();
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑的尾巴呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值