Strings????

This is a discussion on Strings???? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I'm having trouble getting strings from the user, eg. cin >> info; User types: Misc info 1 2 3 cout ...

  1. #1
    Unregistered
    Guest

    Strings????

    I'm having trouble getting strings from the user,
    eg.

    cin >> info;

    User types: Misc info 1 2 3

    cout << info;

    output = Misc

    how do i store the whole sentence with spaces???


    "TIA"


    [Borland Turbo C++ 3.0]

  2. #2
    Unregistered
    Guest
    #define MAX_BUFFER 100
    char info[MAX_BUFFER];

    cin.getline(info, MAX_BUFFER);

  3. #3
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    the >> and << operators ignore spaces and newlines.

    you'll have to do what the above posts says but i'll do it in the following way.

    cin.getline(info,100,'\n);

    this will exit if either 100 chars are inputed or enter is pressed, whichever is first.


    PS you should have posted this in the C or C++ forum.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21