Thread: Very simple question

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Very simple question

    Hi,

    Ive only just started learning C++ (yesterday), and ive already come across a problem.

    part of code:
    cout<<"Please Enter your address: ";
    cin>> ady;
    cin.ignore();

    whenever i come to typing in the address part i press enter and it exits cmd.

    So if i wanted somone to type in "gordon street" for entering an address would it be a char, int, or float as a variable?

    sorry if i havent explained very well, im a little confused

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    6
    That would be string type.

    string adr;
    cout << "Enter your address"<<endl;
    cin >> adr;
    cout <<"The address you typed is:"<< adr;



    Goodluck.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    int and float only take numbers, such as 1, 2, 3 ... The only data type left is character array which can contain anything you type on the keyboard and some you can't type.

    when you using the insert operator (the ">>" operator) cin will stop reading at the first space, so if you enter "gordon street" all you will get in the variable is the word "gordon". If you want everything including spaces you need to use getlin() instead
    Code:
    std::string ady;
    cout<<"Please Enter your address: ";
    getline(cin, ady);

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    Thanks Guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM