1 setiosflags操纵符和setf函数
setiosflags操纵符需要插入到输入/出流cout << setiosflags(ios_base:: | ios_base:😃 setf是流对象的成员函数,cout.setf(ios_base:: , ios_base:: )
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define D(a) T << #a << endl; a
ofstream T("output.out");
int main() {
D(int i = 60);
D(float f = 532.56);
D(T << setiosflags(ios_base::showpos);)
D(T << i << " " << f << endl;)
D(T.unsetf(ios_base::showpos);)
D(T << i << " " << f << endl;)
D(T << setiosflags(ios_base::right);)
D(T.fill('*');)
D(T << setw(10) << i << endl;)
D(T.setf(ios_base::uppercase);)
D(T << setiosflags(ios_base::scientific);)
D(T << f << endl;)
D(T << oct << i << endl
<< dec << i << endl
<< hex << i << endl;)
D(T.setf(ios_base::oct, ios_base::basefield);)
D(T << i << endl;)
return 0;
}
输出:
int i = 60
float f = 532.56
T << setiosflags(ios_base::showpos);
T << i << " " << f << endl;
+60 +532.56
T.unsetf(ios_base::showpos);
T << i << " " << f << endl;
60 532.56
T << setiosflags(ios_base::right);
T.fill('*');
T << setw(10) << i << endl;
********60
T.setf(ios_base::uppercase);
T << setiosflags(ios_base::scientific);
T << f << endl;
5.325600E+02
T << oct << i << endl << dec << i << endl << hex << i << endl;
74
60
3C
T.setf(ios_base::oct, ios_base::basefield);
T << i << endl;
74
2 利用cmd修改系统中的文件
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]) {
ifstream in;
in.open(argv[1], ios::binary);
if (!in) {
cout << "cannot open file";
return 1;
}
const int bsz = 1024;
char buf[bsz];
int line = 0;
while (in.getline(buf, bsz)) {
cout << ++line << ":" << buf << endl;
}
return 0;
}
清理解决方案->生成解决方案,放至同一个文件夹 调用cmd,先输入exe文件名,再输入文本文件名
|