English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2007-03-20 05:39:16 · 4 answers · asked by the man the myth the answerer 5 in Computers & Internet Programming & Design

ok for those who have no knowledge of what i'm talking about example if i ask a user to enter a body part but use the code
cin >> bodypart;

and the user enter belly button

instead of just taking in belly and omitting or sending button to the next cin command i want it to be able to do it all in one line

i know about the function cin.getline() but i was wondering if their was a more effective way so i wouldn't have to put a limit on it

2007-03-20 06:51:29 · update #1

4 answers

Can use getline or get to read in whitespace

// this will read in an entire line
string line;
getline(cin,line);

// to read in single characters (including spaces tabs and newline
char ch;
cin.get(ch);

---
If the input line was
" A B\n"

getline(cin,line); // line = " A B"

or

cin.get(ch); // ch = " "
cin.get(ch); // ch = "A"
cin.get(ch); // ch = " "
cin.get(ch); // ch = "B"
cin.get(ch); // ch = "\n"

2007-03-20 06:22:22 · answer #1 · answered by rsmith985 3 · 0 0

Whitespaces means blank space or .......
Add some clear detail and i'll answer u

2007-03-20 05:46:17 · answer #2 · answered by Sachin B 2 · 0 1

use this commands

/t or >>endl; or ;

2007-03-20 06:46:21 · answer #3 · answered by bonnyrox 2 · 0 1

what

2007-03-20 05:43:27 · answer #4 · answered by coolguyy 2 · 0 1

fedest.com, questions and answers