D
Dic4000
ÏÂÃæ³ÌÐò½¨Á¢²»ÁËÎļþ,²»ÖªµÀÄÄÀï³ö´íÁË?
Ö»Ï붨ÒåÒ»¸öfstreamÀàÐÍÀ´Íê³ÉÊäÈëÊä³öµÄ¹¤×÷.
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
fstream file("a.txt",fstream::in|fstream:ut|fstream::app);
string s1,s2;
if(!file) cerr<<"error"<<endl; //why the program have
//error when connecting
up "a.txt"
s1="abcd 1234\n";
file<<s1; //why don't write in a.txt?
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2<<endl;//s2 is empty
file.close();
getch();
return 0;}
the program can run without any error,but the result is:
error
s2=
the program don't create file "a.txt",How do i do?
Ö»Ï붨ÒåÒ»¸öfstreamÀàÐÍÀ´Íê³ÉÊäÈëÊä³öµÄ¹¤×÷.
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
fstream file("a.txt",fstream::in|fstream:ut|fstream::app);
string s1,s2;
if(!file) cerr<<"error"<<endl; //why the program have
//error when connecting
up "a.txt"
s1="abcd 1234\n";
file<<s1; //why don't write in a.txt?
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2<<endl;//s2 is empty
file.close();
getch();
return 0;}
the program can run without any error,but the result is:
error
s2=
the program don't create file "a.txt",How do i do?