GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Mar-2006, 06:33
Capnpooh Capnpooh is offline
New Member
 
Join Date: Mar 2006
Posts: 1
Capnpooh is on a distinguished road

Noob C++ question


I was working through a tutorial and making really noob programs that when you inout an integer it would give out a reply. I was wondering if there was any thing i could use instead of the INT tag so that the user could input entire words.
Exe: so i can type in my name and it would reply whateever i want, like Your the Man!

Thanks for your time!
  #2  
Old 30-Mar-2006, 07:10
davis
 
Posts: n/a

Re: Noob C++ question


Quote:
Originally Posted by Capnpooh
I was working through a tutorial and making really noob programs that when you inout an integer it would give out a reply. I was wondering if there was any thing i could use instead of the INT tag so that the user could input entire words.
Exe: so i can type in my name and it would reply whateever i want, like Your the Man!

Thanks for your time!

CPP / C++ / C Code:
#include <iostream>
#include <string>

int main()
{
    std::cout << "Enter your name: ";
    std::string you;
    std::cin >> you;
    std::cout << "You da man " << you << std::endl;

    return 0;
}

// output:

Enter your name: Capnpooh
You da man Capnpooh

...because "your" the man is actually you're the man.


:davis:
  #3  
Old 30-Mar-2006, 19:25
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: Noob C++ question


if you want the user to be able to enter a string with spaces in it, use getline:
CPP / C++ / C Code:
#include <iostream>
#include <string>

int main()
{
    std::cout << "Enter your name: ";
    std::string you;
    std::getline(std::cin, you); //regular-old-cin stops at a space; getline doesn't
    std::cout << "You da man " << you << std::endl;

    return 0;
}

// output:

Enter your name: Capnpooh The Third
You da man Capnpooh The Third
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Noob question on c arrays and functions brett C Programming Language 1 20-Apr-2005 03:59
non-member function question crq C++ Forum 1 03-Feb-2005 21:59
Simple question on arrays--please help! brookeville C++ Forum 16 17-Nov-2004 23:23
Repetition structure problem and question brookeville C++ Forum 17 29-Oct-2004 17:48
noob question of % escape sequence. teimu C Programming Language 14 27-Feb-2004 08:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.