Thread: string

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    20

    string

    Code:
    #include <iostream>
    using namespace std;
    void input_string( string &s)
    {
    	cout << "input string s = ";
    	cin >> s;
    	cout << s;
    }
    input : ha ha ha
    why output: ha ???
    I want output ha ha ha. help me problem this?

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    The stream (cin) only copies characters until it hits whitespace, when using the operators. Maybe you want:

    Code:
    std::getline(cin, s);
    Last edited by Dae; 09-28-2009 at 02:59 AM. Reason: oops, posted c-style string getline
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    error
    -No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by akaile View Post
    error
    -No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    Sorry, wrong getline, try this one:

    getline - C++ Reference
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    good. thanks very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM