Question about ofstream & ifstream in Ubuntu

Hello.

I use Eclipse C/C++ in Ubuntu 10.04 to develope my program.

but I found it different to operate files in Linux from in WindowsXP.

here is part of my code:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
p1.h:

class ABC{
//......
public:
  static ofstream fout;
  static void f();
//......
};

p1.cpp:
#include "p1.h"
ofstream ABC::fout;

void ABC::f{
  fout<<"test\n";
}

main.cpp:
#include "p1.h"
void main(){
  fout.open("a.out");
  ABC::f();
  fout.close();
}



and then the problem occurs:
1.it won't automatically create a new file named a.out.
2.if I manually create it, it'll be still empty after run this program.

I am confused about this.

In WindowsXP it works well but in Ubuntu10.04 problems occurs.

Hope some one can help me.

Thanks.
There really is no need to use Eclipse unless you want to.

In any *nix environment, the command-line (plus an editor like vim or emacs or ed) is your IDE!

Just type in your favorite shell:
gcc -o my_a_out pl.cpp main.cpp -lstdc++

Of course, if it gets more complicated, you will want to use gnu make or some other build/dependency system.
Last edited on
Topic archived. No new replies allowed.