By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

How to divide the strings as a group of characters?

P: 8
I do not know how to divide/read the strings into several groups of characters so that i could place these groups into the vector.
Feb 21 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,510
I do not know how to divide/read the strings into several groups of characters so that i could place these groups into the vector.
are you working in C or C++. If C++ you could read successive words into strings which can be stored in a vector, e.g.
Expand|Select|Wrap|Line Numbers
  1.     string s;
  2.     cin >> s;
  3.  
if you typed
hello how are you

the string s would contain the first word "hello"
Feb 21 '07 #2

P: 8
arf
I use C++. What i mean is if i have two strings and each string will end with '\n', how will i read the characters for each string without ignoring the newline?

Example of strings

"3332 2223 2224 5443" //string 1
"6654 5522 3432 6754" //string 2
Feb 21 '07 #3

Expert 100+
P: 1,510
I use C++. What i mean is if i have two strings and each string will end with '\n', how will i read the characters for each string without ignoring the newline?

Example of strings

"3332 2223 2224 5443" //string 1
"6654 5522 3432 6754" //string 2
to read a line of text terminated by a \n use genline() see
http://www.cppreference.com/cppstring/getline.html

e.g.
Expand|Select|Wrap|Line Numbers
  1.     string s;
  2.     getline(cin, s);
  3.  
if you typed
hello how are you

the string s would contain the text "hello how are you"
Feb 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.