file1.txt
12
34
56
输出:file2.txt
56
34
12
char ch[80];
vector<string> sv;
ifstream file1("C:\\file1.txt");
ofstream file2("C:\\file2.txt");
if(!file1)
{
cout << "no";
}else{
while(file1.getline(ch,80))
{
sv.push_back(ch);
}
for(int i=sv.size()-1; i>-1; i--)
{
file2 << sv[i] << endl;
}
file1.close();
file2.close();
}
二、读取配置文件:
static bool loading_config(const char * config_file)
{
string varstr;每一个 >> 操作符读取数据 按空格符或者换行符
ifstream ss;
ss.open(config_file);
string name;
int age;
string school;
string year;
ss >> varstr;
ss >> name;
ss >> varstr;
ss >> age;
ss >> varstr;
ss >> school;
ss >> year;
cout << "name:" << name << endl;
cout << "age:" << age << endl;
cout << "school:" << school << endl;
cout << "year:" << year << endl;
ss.close();
return true;
}
注意string类c_str的使用