1. 文件读取:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream in("test.txt");
int N ;
in>>N;
}
2. double 保留小数点后几位
#include <iostream>
#include <string>
using namespace std;
int main(){
double a=1.234563;
//保留4位有效数字,将得到的数字转变为字符串
char c[256];
sprintf(c, "%.4f", a);//可以四舍五入
cout<<c<<endl;
}
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
int main(){
double a=1.234563;
//保留4位有效数字,将得到的数字转变为字符串,而且还可以四舍五入
stringstream ss;
ss<<setiosflags(ios::fixed)<<setprecision(4)<<a;
string s = ss.str();
cout<<s<<endl;
}
3. 读取文件的一行
#include <i