string array to dat file issues

Apr 19, 2022 at 6:59am
Hello there, i'm having difficulties when importing string array of 18 columns to dat file.
It crashes in 30% times... Why does it happen?
I guess it must be columns quantity.



Apr 19, 2022 at 7:04am
Impossible to say without seeing the code.
Apr 19, 2022 at 7:10am
its just simple set and get functions which take array and put to dat.. To dirty to be posted :)
Apr 19, 2022 at 7:17am
At least show when you read from the file, or write to the file, whichever it is that is causing problems.

If you don't want to post the whole code (which you should try to avoid anyway if you have a lot of code) you could create a self-contained minimal example. So just remove everything that is irrelevant to the problem that you want to show. The code should still compile and run with the problem that you're having. In the process of doing this it's very likely that you will find the problem yourself, but if you still don't see what the problem is you can post it and we will probably be able to help you pretty easily (much more easily than if you had posted the whole program).
Last edited on Apr 19, 2022 at 7:34am
Apr 19, 2022 at 10:01am
Sorry, but my crystal ball is in for service at the moment - so I can't foresee the code in question. So you'll need to post the code in question.
Apr 19, 2022 at 3:57pm
fstream saveToMain( "file.dat", ios::in | ios::out | ios::binary );



Database record;

saveToMain.seekg( ( 0 ) * sizeof( Database ) );
saveToMain.seekp( ( 0 ) * sizeof( Database ) );

ACCOUNT_NUMBER = "100";
id = "1000";
type = "regular";

record.setAccountNumber(ACCOUNT_NUMBER);
record.setId(id);
record.setType(type);

saveToMain.write( reinterpret_cast< const char * >( &record ),
sizeof( Database ) );

I've tried to read from created dat file and I'm always having crashes.
Even if i use only three columns
Apr 19, 2022 at 4:26pm
What is the definition of Database?
Apr 19, 2022 at 4:33pm
Note that if Database contains pointers (or objects that contain pointers) then only the addresses stored in those pointers will be written to file. The actual data that the pointers point to will not be written.
Last edited on Apr 19, 2022 at 4:33pm
Topic archived. No new replies allowed.