Code::blocks data file

i use Code::blocks to compile my C++ programs how ever in this program of mine the Data File Codes does not seem to work. There must be a bug that i can't find.
The bugs are commented in the code (line 206 , 251)

Any help would be appreciated.
Thank You .

The code can be found here..http://pastebin.com/46gn6Qts
Last edited on
Delete the semicolon at line 205.

If there is already a newline character in the input buffer when you get to line 251, then control will fall right through. Look at whatever is getting input BEFORE that and make sure you're consuming any newline characters.
cant delete the semicolon in line 205. Its a part of class definition.

the error in line 251 has been fixed..however i still can't figure how to get the code to write anything into the data file.

i have updated the code ....
thanks in advance
Last edited on
Anything? Does the file get created? If yes, is it 0 bytes long?

I believe that this reproduces the actual error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <fstream>
#include <string>

struct Foo {
  std::string gaz;
  Foo() : gaz( "Hello" ) {}
};

int main() {
  Foo bar;
  using std::ios;
  std::ofstream filout("data.bin",ios::out|ios::app|ios::binary);
  filout.write( (char *) &bar, sizeof(Foo) );
  return 0;
}

It compiles cleanly and execution creates an 8-byte data file. There is no "Hello" within those 8 bytes. An edit of Foo::Foo() to initalize Foo::gaz with "Hello world!" still creates an 8-byte file. I could write an entire novel into gaz and it would not change the size of Foo one bit.

Think about this: Where does std::string put the text that it holds?
Topic archived. No new replies allowed.