标签:img null close 图片 清除 test 表示 flag oid
#include<iostream>
using namespace std;
int main()
{
ios_base::fmtflags original_flags=cout.flags();//保存格式化参数
cout<<812<<"|";
cout.setf(ios_base::left,ios_base::adjustfield);//设置标志位 ,左对齐
cout.width(10);//设置数据域宽度
cout<<813<<815<<‘\n‘;
cout.unsetf(ios_base::adjustfield);//清除标志位
cout.precision(2);//设置显示精度
cout.setf(ios_base::uppercase|ios_base::scientific);//设置标志位 ,十六进制,浮点数方式输出
cout<<813.0;
cout.flags(original_flags);
return 0;
}
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream out("test1.txt");
if(!out)
{
cout<<"fail to open"<<endl;
return 1;
}
out<<"已成功写入文件";
out.close();
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string s;
ifstream in("test1.txt");
if(!in){
cout<<"fail to open"<<endl;
return 1;
}
in>>s;
cout<<s;
in.close();
return 0;
}
#include<iostream>
#include<vector>
#include<time.h>
#include<fstream>
#include<stdlib.h>
using namespace std;
struct student{
int num;
string number,name,cla;
}stu;
void output(student &stu)
{
cout<<stu.num<<" "<<stu.number<<" "<<stu.name<<" "<<stu.cla<<endl;
}
int main()
{
int i;
ifstream in("list.txt");
if(!in){
cout<<"fail to open"<<endl;
return 1;
}
vector<student>a;
for(i=0;i<83;i++)
{
in>>stu.num>>stu.number>>stu.name>>stu.cla;
a.push_back(stu);
}
srand(unsigned(time(NULL)));
for(i=0;i<5;i++)
{
int j=rand()%83;
output(a[j]);
cout<<endl;
}
in.close();
return 0;
}
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int main()
{
ifstream in("english.txt");
if(!in){
cout<<"fail to open"<<endl;
return 1;
}
int words=0,lines=0,charnum=0;
string w;
while(getline(in,w)){
const char *p=w.c_str();
for(int i=0;i<w.length();i++)
{
if(p[i]==‘ ‘) words++;
}
words++;
lines++;
charnum+=w.size();
}
cout<<"单词数:"<<words<<" "<<"行数:"<<lines<<" "<<"字符数:"<<charnum<<endl;
in.close();
return 0;
}
标签:img null close 图片 清除 test 表示 flag oid
原文地址:https://www.cnblogs.com/zengiai/p/9198438.html