C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 8th, 2008, 07:24 PM
bobber205's Avatar
bobber205 bobber205 is offline
Career Newbie
Dev Shed Novice (500 - 999 posts)
 
Join Date: Dec 2005
Location: Klamath Falls, Oregon
Posts: 628 bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 9 h 7 m 40 sec
Reputation Power: 5
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205
'\' 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();

Reply With Quote
  #2  
Old May 8th, 2008, 08:53 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,418 Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 47 m 27 sec
Reputation Power: 334
Code:
outfile.write(reinterpret_cast<char*>(&prefs),sizeof(PREFERENCES));
It looks like you're trying to write a raw struct containing pointer data directly to an output file. This never works. It's not the pointer itself you want to save (which is only meaningful during this one invocation of your program), but the data it points to.

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.

Reply With Quote
  #3  
Old May 8th, 2008, 09:36 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,063 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 13 h 19 m 45 sec
Reputation Power: 1442
You need to serialize that information. Consider overloading the insertion operator, or similar.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
  #4  
Old May 9th, 2008, 04:23 AM
IamPatrick IamPatrick is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 145 IamPatrick Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 5 h 2 m 30 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old May 11th, 2008, 11:59 AM
Fuial Fuial is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 Fuial New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 43 m 31 sec
Reputation Power: 0
try using c striung instead the string or viceversa, and dont do a cast exept it is realy necesary
Comments on this post
sizablegrin disagrees: Get real.

Reply With Quote
  #6  
Old May 11th, 2008, 05:24 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,063 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 13 h 19 m 45 sec
Reputation Power: 1442
@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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > '\' messing up Binary Writing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway