"Di*****@163.com" wrote:
>
.... snip incomprehensible ...
>
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
fstream file("a.txt",fstream::in|fstream::out|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:
Don't believe you.
junk.c:1:19: iostream: No such file or directory (ENOENT)
junk.c:2:18: conio.h: No such file or directory (ENOENT)
junk.c:3:18: fstream: No such file or directory (ENOENT)
junk.c:5: parse error before "namespace"
junk.c:5: warning: type defaults to `int' in declaration of `std'
junk.c:5: ISO C forbids data definition with no type or storage
class
junk.c: In function `main':
junk.c:9: `fstream' undeclared (first use in this function)
junk.c:9: (Each undeclared identifier is reported only once
junk.c:9: for each function it appears in.)
junk.c:9: parse error before "file"
junk.c:10: `string' undeclared (first use in this function)
junk.c:12: `file' undeclared (first use in this function)
junk.c:12: `cerr' undeclared (first use in this function)
junk.c:12: `endl' undeclared (first use in this function)
junk.c:12: parse error before '/' token
junk.c:17: `s1' undeclared (first use in this function)
junk.c:17: parse error before '/' token
junk.c:17:24: missing terminating ' character
junk.c:17:24: warning: character constant too long
junk.c:20: `s2' undeclared (first use in this function)
junk.c:21: `cout' undeclared (first use in this function)
junk.c:21: parse error before '/' token
junk.c:25: warning: implicit declaration of function `getch'
c != C++
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>