主题:简单文件输入输出问题
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int w;
ofstream fout;
ifstream fin;
char name[50];
char ch;
int count=0;
fout.open("q.txt");
fout<<"qwertygh34dfg3fs4"<<endl;
fout.close();
//////////////////////////////////////////////////////////////////////////
cout<<"Please input the name of the file which you want to open"<<endl;
cin.getline(name,50);
fin.open(name);
if(!fin.is_open())
{
cout<<"could not open the file "<<name<<endl;
cout<<"Program terminating."<<endl;
exit(EXIT_FAILURE);
}
fin>>ch;
while(fin.good())
{
count++;
fin>>ch;
}
fin.close();
cin>>w;
return 0;
}
我调试过程序,程序有从先前建立的文本中读入信息,但没在屏幕上显示
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int w;
ofstream fout;
ifstream fin;
char name[50];
char ch;
int count=0;
fout.open("q.txt");
fout<<"qwertygh34dfg3fs4"<<endl;
fout.close();
//////////////////////////////////////////////////////////////////////////
cout<<"Please input the name of the file which you want to open"<<endl;
cin.getline(name,50);
fin.open(name);
if(!fin.is_open())
{
cout<<"could not open the file "<<name<<endl;
cout<<"Program terminating."<<endl;
exit(EXIT_FAILURE);
}
fin>>ch;
while(fin.good())
{
count++;
fin>>ch;
}
fin.close();
cin>>w;
return 0;
}
我调试过程序,程序有从先前建立的文本中读入信息,但没在屏幕上显示