|
2011-10-08
, 16:09
|
|
Posts: 254 |
Thanked: 146 times |
Joined on Dec 2010
@ Antwerp Belgium
|
#2
|
Hi
Is it possible to read all the words from a line in c++?
I mean, I got a line
but it also can beCode:blacklist = mediaplayer Conky
so the items number can change randomly\Code:blacklist = mediaplayer Conky osso-xterm pygtkeditor
Is it possible to read 'em all no matter how many they are?
|
2011-10-08
, 16:28
|
Posts: 3,328 |
Thanked: 4,476 times |
Joined on May 2011
@ Poland
|
#3
|
blacklist = Conky mediaplayer
blacklist
Conky
mediaplayer
|
2011-10-08
, 17:45
|
|
Posts: 254 |
Thanked: 146 times |
Joined on Dec 2010
@ Antwerp Belgium
|
#4
|
Yes. this is what I'm talking about
I wanna read this with getline and have from
as std::string each
Do you understand?
|
2011-10-11
, 15:47
|
Posts: 3,328 |
Thanked: 4,476 times |
Joined on May 2011
@ Poland
|
#5
|
|
2011-10-11
, 16:18
|
Posts: 115 |
Thanked: 342 times |
Joined on Dec 2010
|
#6
|
Yes. this is what I'm talking about
I wanna read this with getline and have from
Code:blacklist = Conky mediaplayerCode:blacklistCode:Conkyas std::string eachCode:mediaplayer
Do you understand?
#include <iostream> #include <sstream> #include <vector> using namespace std; vector<string> split(string &str) { vector<string> tmp; stringstream stream; stream << str.erase(9,2); string cache; while(getline(stream, cache, ' ')) { tmp.push_back(cache); } return tmp; } int main(void) { std::string d= "blacklist = Conky mediaplayer"; vector<string> blisted = split(d); cout << blisted[0]; //blacklist cout << blisted[1]; //Conky cout << blisted[2]; //mediaplayer }
|
2011-10-11
, 16:50
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#7
|
Code:#include <iostream> #include <sstream> #include <vector> using namespace std; vector<string> split(string &str) { vector<string> tmp; stringstream stream; stream << str.erase(9,2); string cache; while(getline(stream, cache, ' ')) { tmp.push_back(cache); } return tmp; } int main(void) { std::string d= "blacklist = Conky mediaplayer"; vector<string> blisted = split(d); cout << blisted[0]; //blacklist cout << blisted[1]; //Conky cout << blisted[2]; //mediaplayer }
|
2011-10-11
, 16:50
|
|
Posts: 738 |
Thanked: 983 times |
Joined on Apr 2010
@ London
|
#8
|
while (stream) { cache << stream; tmp.push_back(cache); }
|
2011-10-11
, 17:36
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#9
|
The Following 2 Users Say Thank You to nicolai For This Useful Post: | ||
Is it possible to read all the words from a line in c++?
I mean, I got a line
Is it possible to read 'em all no matter how many they are?