feat: 统一 cpp 文件编码格式为 utf-8
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//用cin输入字符串数据时,如果字符串中含有空白就不能完整输入。因为遇到空白字符时,cin就认为字符串结束了。
|
||||
//用cin输入字符串数据时,如果字符串中含有空白就不能完整输入。因为遇到空白字符时,cin就认为字符串结束了。
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(int argc, char const *argv[])
|
||||
@@ -11,8 +11,8 @@ int main(int argc, char const *argv[])
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
若a的内容是:
|
||||
若a的内容是:
|
||||
this is a string!
|
||||
就难以输入啦!
|
||||
这样的数据应用输入流类的成员函数输入
|
||||
就难以输入啦!
|
||||
这样的数据应用输入流类的成员函数输入
|
||||
*/
|
||||
@@ -1,6 +1,6 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
//º¯ÊýÔÐÍ
|
||||
//函数原型
|
||||
//put(char c)
|
||||
//write(const char*c, int n)
|
||||
int main(){
|
||||
|
||||
@@ -7,11 +7,11 @@ int main(){
|
||||
double d=-1234.8976;
|
||||
cout<<setw(30)<<left<<setfill('*')<<c<<"----L1"<<endl;
|
||||
cout<<setw(30)<<right<<setfill('*')<<c<<"----L2"<<endl;
|
||||
//showbase显示数值的基数前缀
|
||||
//showbase显示数值的基数前缀
|
||||
cout<<dec<<showbase<<showpoint<<setw(30)<<d<<"----L3"<<"\n";
|
||||
//showpoint显示小数点
|
||||
//showpoint显示小数点
|
||||
cout<<setw(30)<<showpoint<<setprecision(10)<<d<<"----L4"<<"\n";
|
||||
//setbase(8)设置八进制
|
||||
//setbase(8)设置八进制
|
||||
cout<<setw(30)<<setbase(16)<<100<<"----L5"<<"\n";
|
||||
system("pause");
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ int main(int argc, char const *argv[])
|
||||
{
|
||||
fstream ioFile;
|
||||
ioFile.open("./a.dat",ios::out);
|
||||
ioFile<<"张三"<<" "<<76<<" "<<98<<" "<<67<<endl; //L3
|
||||
ioFile<<"李四"<<" "<<89<<" "<<70<<" "<<60<<endl;
|
||||
ioFile<<"王十"<<" "<<91<<" "<<88<<" "<<77<<endl;
|
||||
ioFile<<"黄二"<<" "<<62<<" "<<81<<" "<<75<<endl;
|
||||
ioFile<<"刘六"<<" "<<90<<" "<<78<<" "<<67<<endl;
|
||||
ioFile<<"张三"<<" "<<76<<" "<<98<<" "<<67<<endl; //L3
|
||||
ioFile<<"李四"<<" "<<89<<" "<<70<<" "<<60<<endl;
|
||||
ioFile<<"王十"<<" "<<91<<" "<<88<<" "<<77<<endl;
|
||||
ioFile<<"黄二"<<" "<<62<<" "<<81<<" "<<75<<endl;
|
||||
ioFile<<"刘六"<<" "<<90<<" "<<78<<" "<<67<<endl;
|
||||
ioFile.close();
|
||||
ioFile.open("./a.dat",ios::in|ios::binary);
|
||||
char name[10];
|
||||
int chinese,math,computer;
|
||||
cout<<"姓名\t"<<"英语\t"<<"数学\t"<<"计算机\t"<<"总分"<<endl;
|
||||
cout<<"姓名\t"<<"英语\t"<<"数学\t"<<"计算机\t"<<"总分"<<endl;
|
||||
ioFile>>name;
|
||||
while(!ioFile.eof()) {
|
||||
ioFile>>chinese>>math>>computer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//【例12-2】 用函数get和getline读取数据。
|
||||
//【例12-2】 用函数get和getline读取数据。
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
@@ -14,8 +14,8 @@ int main()
|
||||
}
|
||||
|
||||
/*
|
||||
用法:a = cin.get() ?或者 ?cin.get(a)
|
||||
结束条件:输入字符足够后回车
|
||||
说明:这个是单字符的输入,用途是输入一个字符,把它的ASCALL码存入到a中
|
||||
处理方法:与cin不同,cin.get()在缓冲区遇到[enter],[space],[tab]不会作为舍弃,而是继续留在缓冲区中
|
||||
用法:a = cin.get() ?或者 ?cin.get(a)
|
||||
结束条件:输入字符足够后回车
|
||||
说明:这个是单字符的输入,用途是输入一个字符,把它的ASCALL码存入到a中
|
||||
处理方法:与cin不同,cin.get()在缓冲区遇到[enter],[space],[tab]不会作为舍弃,而是继续留在缓冲区中
|
||||
*/
|
||||
@@ -1,9 +1,9 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
/*
|
||||
(1)cin.getline(arrayname,size)与cin.get(arrayname,size)的区别
|
||||
cin.get(arrayname,size)当遇到[enter]时会结束目前输入,他不会删除缓冲区中的[enter]
|
||||
cin.getline(arrayname,size)当遇到[enter]时会结束当前输入,但是会删除缓冲区中的[enter]
|
||||
(1)cin.getline(arrayname,size)与cin.get(arrayname,size)的区别
|
||||
cin.get(arrayname,size)当遇到[enter]时会结束目前输入,他不会删除缓冲区中的[enter]
|
||||
cin.getline(arrayname,size)当遇到[enter]时会结束当前输入,但是会删除缓冲区中的[enter]
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
@@ -12,27 +12,27 @@ int main()
|
||||
char b;
|
||||
cin.get(a,10);
|
||||
cin.get(b);
|
||||
cout<<a<<endl<<int(b);//输入:12345[enter] 输出:12345 【换行】 10*/
|
||||
cout<<a<<endl<<int(b);//输入:12345[enter] 输出:12345 【换行】 10*/
|
||||
/*char c[10];
|
||||
char d;
|
||||
cin.getline(c,10);
|
||||
cin.get(d);
|
||||
cout<<c<<endl<<int(d);//输入:12345[enter]a[enter] 输出:12345【换行】97*/
|
||||
//cin.getline(arrayname,size,s)与cin.gei(arrayname,size,s)的区别
|
||||
cout<<c<<endl<<int(d);//输入:12345[enter]a[enter] 输出:12345【换行】97*/
|
||||
//cin.getline(arrayname,size,s)与cin.gei(arrayname,size,s)的区别
|
||||
/*
|
||||
cin.getline(arrayname,size,s)当遇到s时会结束输入,并把s从缓冲区中删除
|
||||
cin.get(arrayname,size,s)当遇到s时会结束输入,但不会删除缓冲区中的s
|
||||
cin.getline(arrayname,size,s)当遇到s时会结束输入,并把s从缓冲区中删除
|
||||
cin.get(arrayname,size,s)当遇到s时会结束输入,但不会删除缓冲区中的s
|
||||
*/
|
||||
/*
|
||||
char e[10];
|
||||
char f;
|
||||
cin.get(e,10,',');
|
||||
cin.get(f);
|
||||
cout<<e<<endl<<f;//输入:12345,[enter] 输出:12345【换行】,说明:cin,get不会删除缓冲区的,*/
|
||||
cout<<e<<endl<<f;//输入:12345,[enter] 输出:12345【换行】,说明:cin,get不会删除缓冲区的,*/
|
||||
char e1[10];
|
||||
char f1;
|
||||
cin.getline(e1,10,',');
|
||||
cin.get(f1);
|
||||
cout<<e1<<endl<<f1;//输入:asd,wqe 输出:asd【换行】w
|
||||
cout<<e1<<endl<<f1;//输入:asd,wqe 输出:asd【换行】w
|
||||
system("pause");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include<iostream>
|
||||
#include<fstream>
|
||||
//向量是一个能够存放任意类型的动态数组
|
||||
//向量是一个能够存放任意类型的动态数组
|
||||
#include<vector>
|
||||
#include<cstring>
|
||||
using namespace std;
|
||||
@@ -25,20 +25,20 @@ class Person{
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
vector<Person> v;
|
||||
vector<Person>::iterator pos;//声明一个迭代器,来访问vector容器,作用:遍历或者指向vector容器的元素
|
||||
vector<Person>::iterator pos;//声明一个迭代器,来访问vector容器,作用:遍历或者指向vector容器的元素
|
||||
char ch;
|
||||
ofstream out("d:/person.dat",ios::out|ios::app|ios::binary);
|
||||
char Name[20],ID[18],Addr[20];
|
||||
int Age;
|
||||
cout<<"------输入个人档案------"<<endl<<endl;
|
||||
cout<<"------输入个人档案------"<<endl<<endl;
|
||||
do{
|
||||
cout<<"姓名: ";
|
||||
cout<<"姓名: ";
|
||||
cin>>Name;
|
||||
cout<<"身份证号: ";
|
||||
cout<<"身份证号: ";
|
||||
cin>>ID;
|
||||
cout<<"年龄: ";
|
||||
cout<<"年龄: ";
|
||||
cin>>Age;
|
||||
cout<<"地址: ";
|
||||
cout<<"地址: ";
|
||||
cin>>Addr;
|
||||
Person per(Name,ID,Age,Addr);
|
||||
out.write((char*)&per,sizeof(per));
|
||||
@@ -53,7 +53,7 @@ int main(int argc, char const *argv[])
|
||||
v.push_back(s);
|
||||
in.read((char*)&s,sizeof(s));
|
||||
}
|
||||
cout<<"\n---------从文件中读出的数据--------"<<endl<<endl;//L15
|
||||
cout<<"\n---------从文件中读出的数据--------"<<endl<<endl;//L15
|
||||
pos=v.begin();
|
||||
for(pos=v.begin();pos!=v.end();pos++)
|
||||
(*pos).display();
|
||||
|
||||
Reference in New Issue
Block a user