标签:随机种子 precision for cti bubuko width 浮点 cas 字符
11-3
#include<iostream> #include<fstream> using namespace std; int main() { ofstream outfile("D:\\text1.txt"); outfile<<"成功写入文件"<<endl; outfile.close(); return 0; }
11-4
#include<iostream> #include<fstream> #include<string.h> using namespace std; int main() { string file; ifstream outfile("D:\\text1.txt"); outfile>>file; cout<<file<<endl; outfile.close(); return 0; }
11-7
#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);//指定输出宽度10字符 cout<<813<<815<<‘\n‘; cout.unsetf(ios_base::adjustfield);//取消格式 cout.precision(2);//设定输出值以新的浮点数精度值显示,小数点后保留2位 cout.setf(ios_base::uppercase|ios_base::scientific);//更改浮点数的显示方式,以科学显示浮点数值 cout<<831.0; cout.flags(original_flags);//恢复初始的的格式化参数 return 0; }
4
#include<iostream> #include<fstream> #include<string> using namespace std; int main() { ifstream infile("golden god.txt"); int line = 0; int num1 = 0; int word = 0; string s1; int m; while (getline(infile, s1)) { m = s1.size(); line++; num1 += m; for (int i = 0;i < m; i++) { if (s1[i] >= ‘A‘&&s1[i] <= ‘Z‘ || s1[i] >= ‘a‘&&s1[i] <= ‘z‘) { if (s1[i + 1] >= ‘!‘&&s1[i + 1] <= ‘/‘||s1[i+1]==‘ ‘||s1[i+1]>=‘:‘&&s1[i+1]<=‘?‘) { word++; } } } } infile.close(); cout <<"行数:"<< line << " 字符数:" << num1 <<" 单词数:"<<word<< endl; return 0; }
#include<string.h> #include<cstdlib> #include<ctime> using namespace std; struct student { string num1; string num2; string name; string classroom; }; int main() { student stu[100]; ifstream infile("list.txt"); int i=0; while(infile>>stu[i].num1>>stu[i].num2>>stu[i].name>>stu[i].classroom) { i++; } infile.close(); ofstream outfile("roll.txt"); srand((unsigned)time(NULL));//设立随机种子 for(int j=0;j<5;j++)//随机抽取 { int r=rand() %84; cout<<stu[j].num1<<" "<<stu[i].num2<<" "<<stu[j].name<<" "<<stu[j].classroom<<endl; outfile<<stu[j].num1<<" "<<stu[i].num2<<" "<<stu[j].name<<" "<<stu[j].classroom<<endl; } outfile.close(); return 0; }
这一题 数据还是读不出来。。。我个人感觉代码还是没有问题,请大佬指点。。。
标签:随机种子 precision for cti bubuko width 浮点 cas 字符
原文地址:https://www.cnblogs.com/zzy4546/p/9206384.html