实验7
Posted yywzs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验7相关的知识,希望对你有一定的参考价值。
1 #include<iostream> 2 #include<string> 3 #include<fstream> 4 #include<vector> 5 #include<stdlib.h> 6 #include<time.h> 7 using namespace std; 8 struct student{ 9 int id; 10 long long stu_num; 11 string name; 12 string sub; 13 }; 14 int main(){ 15 int i,n; 16 srand(time(NULL)); 17 ifstream readfile("list.txt"); 18 student stu[83]; 19 for(i=0;i<83;i++){ 20 readfile>>stu[i].id>>stu[i].stu_num>>stu[i].name>>stu[i].sub; 21 } 22 readfile.close(); 23 ofstream writefile("roll.txt",ios_base::app); 24 for(i=0;i<5;i++){ 25 n=rand()%82; 26 writefile<<stu[n].id<<" "<<stu[n].stu_num<<" "<<stu[n].name<<" "<<stu[n].sub<<endl; 27 cout<<stu[n].id<<" "<<stu[n].stu_num<<" "<<stu[n].name<<" "<<stu[n].sub<<endl; 28 } 29 writefile.close(); 30 }
1 #include<fstream> 2 #include<iostream> 3 #include<string> 4 using namespace std; 5 int main(){ 6 char s[50]={"test1.txt"}; 7 string f; 8 ofstream file(s,ios::app); 9 file.write("已经成功写入!",sizeof("已经成功写入!")); 10 file.close(); 11 ifstream file2(s); 12 getline(file2,f); 13 cout<<f; 14 file2.close(); 15 return 0; 16 17 }
1 #include<iostream> 2 #include<fstream> 3 #include<string> 4 #include<vector> 5 using namespace std; 6 int main(){ 7 int n=0,i,sum=0; 8 string s,ss; 9 cin>>s; 10 vector <string> str; 11 ifstream readf(s.c_str()); 12 while(getline(readf,ss)){ 13 str.push_back(ss); 14 n++; 15 } 16 for(i=0;i<n;i++){ 17 sum+=str[i].size(); 18 } 19 cout<<"字数:"<<sum<<endl<<"行数:"<<n<<endl; 20 }
以上是关于实验7的主要内容,如果未能解决你的问题,请参考以下文章
20155201 李卓雯 《网络对抗技术》实验一 逆向及Bof基础