Results 1 to 4 of 4

Thread: cin problem II SIMPLE

  1. #1

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Unhappy

    Another question: how can I use cin with strings?
    Code:
    string data;
    cin>>data;   //gives an error
    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you want to use strings then you need to use the proper STL iostreams library:
    Code:
    #include <iostream> /* No .h extension! */
    #include <string>
    using namespace std;
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    if you want to be able to get more than one word(like if somebody typed "hello world" hello would be the only one gathered), do this

    Code:
    	string str;
    	getline(cin,str);
    	cout << str;

  4. #4

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Exclamation ??

    but the user has to press twice on the return button

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width