How can I capture the string in C++?
For example, the input is: Mary Average User
and I can capture the those three words into three variables?
Thx!~
How can I capture the string in C++?
For example, the input is: Mary Average User
and I can capture the those three words into three variables?
Thx!~
Something like this would work -
Code:#include <iostream> #include <string> using namespace std; int main() { string a,b,c; cin >> a >> b >> c; cout << a << endl << b << endl << c << endl; return 0; }
zen
you wanna capture into different variables or into a single one???Originally posted by DramaKing
How can I capture the string in C++?
For example, the input is: Mary Average User
and I can capture the those three words into three variables?
Thx!~
look for a single variable you could use:
what zen said is right...Code:char s[200]; gets(s); //if youre reading from a file then use fgets
Mike
Null Shinji The Sorcerer is here
Evangelion Quotes:
"If youre gonna do it, dont waste time. Otherwise, leave", Gendo
"Release the final safety lock, Evangelion Unit One, Lift Off!!", Misato
"Syncrograph has reversed, pulses are flowing back!!!", Maya
streamload id= nullshinji icq= 12944337; E-M@IL= [email protected]; aim= mayeba
msn= [email protected]
Thx!! The program can put three words in three different variables, how about if I key in two words, the first word will put in varaible "a" and the second word will put in varible c?
Use cin.getline() to get the input as a string then use strtok() or strchr() to split the string up into its constituent words.A search of these boards should throw some light on this.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi