DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: String Input in C++

  1. #1
    Join Date
    Sep 2006
    Posts
    7

    Lightbulb String Input in C++

    hi, i m currently on the file i/o part and then i notced something.
    the cin doesnt accept strings why is that

    e.g.

    string str;
    cin >> str; <----- i get error here
    cout << "you entered .. " << str;
    cin.get();

    the error i get is ..
    no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

    any way to get around that? im trying so that what ever string user enters is saved to a file.. the saving of predefined strings works but not when i try to input something as a string..

    help would be appreciated :)

    :WAVE:

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    you need to use <iostream> and <string>, not anything else. Also make sure that you add a
    using namespace std;
    directive before the cin statement.
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    The compiler is mistaking >> for the binary bit shift operator is my guess, which makes me guess your on visual 6.0 ? It was prone to that error. You can get around it with a cin.operator >> (str) if this is the case (double check my syntax but its close)

  4. #4
    Join Date
    Sep 2006
    Posts
    7

    Thumbs down

    ok so the problem now is that the program doesnt save the string to file like it should be .. for example i type

    hello how are you

    and when i press enter.. it shows up in the file like

    hello
    how
    are
    you

    is there any way i can fix this? im uploading my project this time
    Attached Files Attached Files

Similar Threads

  1. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  2. Replies: 1
    Last Post: 06-05-2001, 06:12 AM
  3. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 12:11 PM
  4. Replies: 0
    Last Post: 06-22-2000, 07:30 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center