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

文件没输出?该怎么解决

2012-03-15 
文件没输出???#include cstdlib#include iostream#include fstream#include vector#include stri

文件没输出???
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

int StrCmp(string a,string b);

int main(int argc, char *argv[])
{
   
  string ches,line,chesa,chesb;
  ofstream out("FILEwrite.cpp");
  char ch;
  for(int i=0;ch!='$';i++)
  {
  printf("input the strings %d \n",i+1);
  cin >> ches;
  out << ches;
  printf("if you want to go on ,press any key but '$' \n"); 
  cin >> ch ;
  }
  vector<string> v;
  int i,j;  
  ifstream in("FILEwrite.cpp");
  while(getline(in,line))
  v.push_back(line);
  for(i=0;i<v.size();i++)
  for(j=i+1;j<v.size();j++)
  {
  chesa=v[i];
  chesb=v[j];
  if(StrCmp(chesa,chesb)>0)
  {
  ches=v[i];
  v[i]=v[j];
  v[j]=ches;  
  }  
  } 
  ofstream outaa(".cpp");
  for(i=0;i<v.size();i++)  
  outaa << v[i] << "\n";  
   
   
  system("PAUSE");
  return EXIT_SUCCESS;
}

int StrCmp(string a,string b)
 {
  int i;
  for(i=0;i<a.size()&&i<b.size();i++)
  if(a[i]>b[i])
  return 1;
  else 
  if(a[i]<b[i])
  return -1;
 }
   
发现FLLEwritea文件里面没内容,什么原因?/

[解决办法]
FLLEwritea 好像没看到有这个文件?
[解决办法]
ofstream outaa(".cpp"); //这个???
[解决办法]
for(int i=0;ch!= '$ ';i++)
{
printf("input the strings %d \n",i+1);
cin > > ches; ==> ch ??
out < < ches; ==> ch??
printf("if you want to go on ,press any key but '$ ' \n"); 
cin > > ch ;
}
[解决办法]
在读文件之前,先关闭文件试试:
......
for(int i=0;ch!= '$ ';i++) 

printf("input the strings %d \n",i+1); 
cin > > ches; 
out < < ches; 
printf("if you want to go on ,press any key but '$ ' \n");
cin > > ch ; 

out.close();
vector <string > v; 
int i,j;
ifstream in("FILEwrite.cpp"); 
while(getline(in,line)) 
v.push_back(line); 
......

热点排行