首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

程序哪里出错了 希望大家指教,该如何解决

2012-03-29 
程序哪里出错了 希望大家指教// 文件操作.cpp : 定义控制台应用程序的入口点。//#include stdafx.h#inclu

程序哪里出错了 希望大家指教
// 文件操作.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int main()
{
ifstream infile("d:\\123.txt");
if(!infile)
{
cout<<"cannot open the file"<<endl;
}
ostringstream os;
os<<infile.rdbuf();
vector<string>vec;
vec.push_back(os.str());
reverse(vec.begin(),vec.end());
ofstream outfile("456.txt");
if(!outfile)
{
cout<<"cannnot open the file"<<endl;
}
for(int i = 0 ; i < vec.size();i++)
outfile<<vec[i];
return 0;
}
比如123.txt 里面的为123 存在456.txt 为321 但是程序跑完 456.txt 中为123

[解决办法]
vector里面只有一个元素,reverse有什么用?
要对string进行反转:
vector<string> vec;
string str = os.str();
reverse(str.begin(),str.end());
vec.push_back(str);

热点排行