Thread: Problem with cin

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Question Problem with cin

    Greetings,

    Whenever I compile and run a program (as seen below), after I enter the input, the program stops, and doesn't run the last cout. Is the answer totally obvious, or is there something I've overlooked? It compiles all fine and dandy...

    Code:
    #include <iostream.h>
    
    int main()
    {
    char *message;
    cout <<"Enter a sentence: ";
    cin >> message;
    cout <<"\nYou said " << message;
    return 0;
    }
    Oh, and by the way, I'm running Windows XP and using Bloodshed Dev-C++ 4

    Much confused ( ),
    -IEatGreyFoxes.

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Try defining message as
    char message[80];
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    almost...

    That solution works.. in a way.

    It ignores anything after (including as well) a space. Anything else that could solve this?

    -IEatGreyFoxes
    Last edited by IEatGreyFoxes; 03-28-2004 at 11:47 PM. Reason: Somethings a bit unclear

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    you need to use getline
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Thumbs up yay!

    It works! Hooray!

    Thankyou for your time helping me out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with cin. Please help me.
    By Antigloss in forum C++ Programming
    Replies: 17
    Last Post: 06-06-2005, 09:50 AM
  2. Input File HELP, weird problem
    By gravity-1 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2005, 08:43 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Problem with cin
    By ErionD in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 11:27 AM