|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
'\' messing up Binary Writing
Whenver I have \ in my strings, I cannot write successfully to a binary. In the example below I end up with a bunch of nothing. Weird characters like those classic blocks and ˆQ:. Stuff like that.
![]() If I have just have regular text it writes fine. Note that PREFERENCES is a struct with two strings in it. Code:
prefs.kmplayerLocation = string("C:\\Program Files\\The KMPlayer\\KMPlayer.exe");
prefs.vlcLocation = string("C:\\Program Files\\VideoLAN\\VLC\\vlc");;
//prefs.kmplayerLocation = "dfasfddas";
//prefs.vlcLocation = "fdafds";
ofstream outfile;
outfile.open("preferences.data",ios::out|ios::binary);
outfile.write(reinterpret_cast<char*>(&prefs),sizeof(PREFERENCES));
outfile.close();
|
|
#2
|
|||
|
|||
|
Code:
outfile.write(reinterpret_cast<char*>(&prefs),sizeof(PREFERENCES)); Note that your struct will contain pointer data even if it doesn't explicitly have members that are pointers if it contains an instance of pretty much any nontrivial STL class (such as std::string), since those will have pointer data themselves. |
|
#3
|
||||
|
||||
|
You need to serialize that information. Consider overloading the insertion operator, or similar.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread). |
|
#4
|
|||
|
|||
|
If the compiler is telling you there is an error, listen to it, don't hide the error behind a reinterpret(or other)_cast unless you have a very good reason for doing so.
|
|
#5
|
|||
|
|||
|
try using c striung instead the string or viceversa, and dont do a cast exept it is realy necesary
|
|
#6
|
||||
|
||||
|
@Fuial: what the hell kind advice is that? "Do this. If that doesn't work do the opposite!"
Voodoo is not a commonly accepted technique for programming correctly. One drawback is that it requires a lot of chickens to support the indiscrimant slaughter. Stick to farming. Chicks are cheap compared to buggy, glitchy programs. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > '\' messing up Binary Writing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|