Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

logout

splitting a string

This topic is 5227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got a line like this: "this is a line of words that i want to do somthing with" Now I want to convert this into a vector. where each element represent a word.: myVector[0] = "this"; myVector[1] = "is"; myVector[2] = "a"; myVector[3] = "line"; myVector[4] = "of"; ... .. Now I figrued this can be done using stringstreams but im not sure on how i would go about that. Specaly the part of getting the stuff from the SS to the vector. Help plz

Share this post


Link to post
Share on other sites
Advertisement
If you don''t grok stream iterators, a different approach would be:

std::stringstream sstr("this is a line of words that i want to do somthing with");
std::vector<std::string> words;
while (sstr.good()) {
std::string temp;
sstr >> temp;
words.push_back(temp);
}


There''s also the difficult to use and error prone strtok() function in the standard C library.

Share this post


Link to post
Share on other sites
quote:
Original post by Charleh
Just out of curiosity, whats a grok?


Jargon File

grok: /grok/, /grohk/, vt

[common; from the novel Stranger in a Strange Land, by Robert A. Heinlein, where it is a Martian word meaning literally ‘to drink’ and metaphorically ‘to be one with’] The emphatic form is grok in fullness.

1. To understand. Connotes intimate and exhaustive knowledge. When you claim to ‘grok’ some knowledge or technique, you are asserting that you have not merely learned it in a detached instrumental way but that it has become part of you, part of your identity. For example, to say that you “know” LISP is simply to assert that you can code in it if necessary — but to say you “grok” LISP is to claim that you have deeply entered the world-view and spirit of the language, with the implication that it has transformed your view of programming. Contrast zen, which is similar supernal understanding experienced as a single brief flash. See also glark.

2. Used of programs, may connote merely sufficient understanding. “Almost all C compilers grok the void type these days.”


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)


[edited by - Fruny on February 28, 2004 2:13:11 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!