manhattan.txt
15.33 21.11 3.00 10.32
mami.txt
11.33 91.11 13.00 20.32
IO.cpp
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream mia;
/* 不知为什么和书上一样的代码,就是默认路径输出文件,必须指定文件路径才可。在网上找了一大圈无果。
* 本想在优快云提问,看到那个发帖的界面瞬间就什么都不想写了,不管是发帖还是发博客总之优快云的用户体验
* 做的实在是不能再差了,不过和其他类似的国内网站比较的话,优快云还算好一点。
* /
mia.open("/Users/br/Documents/C:C++/character/character/manhattan.txt");
if (mia.fail()) {
cout << "mia opening failed.";
exit(EXIT_FAILURE);
}
mia.setf(ios::fixed);
mia.setf(ios::showpoint);
mia.precision(2); //显示两位小数点
mia << 15.33 << " " << 21.11111 << " " << 3.0009 << " " << 10.32187 << endl;
ofstream coch;
coch.setf(ios::fixed);
coch.setf(ios::showpoint);
/* 删除 coch.setf(ios::fixed); coch.setf(ios::showpoint);
* 则 coch.precision(2); 为显示两位数,如: 11.33 显示为:11;
* /
coch.precision(2);
coch.open("/Users/br/Documents/C:C++/character/character/mami.txt");
coch << 11.33 << " " << 91.11111 << " " << 13.0009 << " " << 20.32187 << endl;
mia.close();
coch.close();
return 0;
}