Spaces in Console

Started by
52 comments, last by XDarkScar 21 years ago
yea I know a noob question, I know its not string, int, char didn''t work what the hell is it??? Easy way of programming: Code, Graphics, Swearing....
Easy way of programming: Coding, Debugging, Swearing.
Google / Game Tutorials / GameDev.Net / My Project server. Check it out.
Project: N/A / Percent Complete: 0% / Due Date: N/A
Advertisement
What are you talking about?
std::cout << '' ''; ???

Craaazzzy boy. :/

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
//all teh crap above...void main(){??? name;cout << "Enter name: ";cin >> name;cout << name;}see whats the varible...    


Easy way of programming: Code, Graphics, Swearing....
Easy way of programming: Coding, Debugging, Swearing.
Google / Game Tutorials / GameDev.Net / My Project server. Check it out.
Project: N/A / Percent Complete: 0% / Due Date: N/A

std::cout << "Enter name: ";
char name[20];
std::cin >> name;

std::cout << "Your name is " << name << ''\n'';


yet I would recommend:


std::cout << "Enter name: ";
std::string name;
std::cin >> name;

std::cout << "Your name is " << name << ''\n'';


There are, though, a number of different approaches.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
And what does this have to do with a space???

What makes you think it''s not string?
its not working.... lol U put in bob smith
out comes bob...
whats wrong here

[edited by - XDarkScar on April 18, 2003 2:16:58 PM]
Easy way of programming: Coding, Debugging, Swearing.
Google / Game Tutorials / GameDev.Net / My Project server. Check it out.
Project: N/A / Percent Complete: 0% / Due Date: N/A
omg I said it wrong..... Mean takes spaces like bob smith out comes bob smith

Easy way of programming: Code, Graphics, Swearing....
Easy way of programming: Coding, Debugging, Swearing.
Google / Game Tutorials / GameDev.Net / My Project server. Check it out.
Project: N/A / Percent Complete: 0% / Due Date: N/A
If you are using std::string:


std::cout << "Enter name: ";
std::string name;
std::getline(std::cin, name, '\n');

std::cout << "Your name is " << name << std::endl;


or, if not:


std::cout << "Enter name: ";
char name[20];
std::cin.getline(name, 20);

std::cout << "Your name is " << name << std::endl;


It is to do with input streams (buffers); have a look on Google for more.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on April 19, 2003 10:11:19 AM]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
K, do you know how to speak english well? do you know how to articulate a question well?

do you mean "bob smith " becomes "bob smith"? i.e. trailing whitespace is being eliminated?

This topic is closed to new replies.

Advertisement