标签:struct iostream get .com 格式 输出 写入 使用 img
#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);//设置精度 cout.setf(ios_base::uppercase | ios_base::scientific);//使用科学计数法输出。 cout << 831.0; cout.flags(original_flags);//恢复初始参数 return 0; }
11-3
#include<iostream> #include<fstream> using namespace std; int main() { ofstream a("test1.txt"); a << "已成功写入文件!"; a.close(); return 0; }
11-4
#include<iostream> #include<fstream> #include<string> using namespace std; int main() { ifstream a("test1.txt"); string s; a >> s; cout << s; return 0; }
2
#include<iostream> #include<fstream> #include<string> #include<cstdlib> #include<ctime> using namespace std; struct { int n; string j, k, l; }s[100]; int main() { ifstream a("list.txt"); int i; for (i = 0; i < 83; i++)a >> s[i].n >> s[i].j >> s[i].k >> s[i].l; a.close(); ofstream b("roll.txt"); srand((unsigned)time(NULL)); for (i = 1; i <= 5; i++) { int m = 1 + rand() % 83; cout << s[m].n << " "<<s[m].j <<" "<< s[m].k <<" "<< s[m].l<<endl; b << s[m].n << " "<<s[m].j <<" "<< s[m].k <<" "<< s[m].l<<endl; } b.close(); return 0; }
3
#include<iostream> #include<fstream> #include<string> using namespace std; int main() { ifstream is("article.txt"); int a = 0; int b = 0; int c = 0; string s; int m; while (getline(is, s)) { m = s.size(); a++; b += m; for (int i = 0; i < m; i++) { if (s[i] >= ‘A‘&&s[i] <= ‘Z‘ || s[i] >= ‘a‘&&s[i] <= ‘z‘) { if (s[i + 1] >= ‘!‘&&s[i + 1] <= ‘/‘ || s[i + 1] == ‘ ‘ || s[i + 1] >= ‘:‘&&s[i + 1] <= ‘?‘) { c++; } } } } is.close(); cout << "Lines:" << a << " Letters:" << b<< " Words:" << c<< endl; return 0; }
标签:struct iostream get .com 格式 输出 写入 使用 img
原文地址:https://www.cnblogs.com/nuist20178303037/p/9203303.html