Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem when reading from buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 15 March 2014 - 06:37 AM

How should I go about reading from an unsigned char array,given that I know the size? Suppose it contained:

 

word

word1

 

I would need to read every word into a separate string. The obvious way is to just loop through it,test if the char is whitespace and go from there.... but I would like to use the std functions...


Edited by noatom, 15 March 2014 - 06:42 AM.


Sponsor:

#2 frob   Moderators   -  Reputation: 22218

Like
1Likes
Like

Posted 15 March 2014 - 06:55 AM

Reading into what?

You are looking at c-style strings in a buffer. Perhaps a stringstream object might be appropriate? stringstream provides lots of useful ways of turning buffers into objects with buffer-style manipulations, stream-style manipulations, and string-style manipulations. Also if you are looking at strings alone, the string constructors might be useful, as might string::append, string::insert and string::assign.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 15 March 2014 - 07:05 AM

ok,let me make it more concise:

 

if I had: "today is a good day" put into an unsigned char array, how would I go about puting every single word into a separate std::string?

 

 

UPDATE: used stringstream as you suggested,and it worked just fine,thanks.


Edited by noatom, 15 March 2014 - 07:11 AM.


#4 Álvaro   Crossbones+   -  Reputation: 13645

Like
3Likes
Like

Posted 15 March 2014 - 07:13 AM

Why are these chars unsigned?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS