struggle...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: struggle...

  1. #1
    Join Date
    Oct 2012
    Posts
    9

    struggle...

    I am using on Dev C++. However, I couldn't figure out it...because I got few errors.

    In function `int StringToNumber(std::string)':
    13 no match for 'operator>' in 'converter > result'

    Anything fix this?

    Thanks,

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    #include <conio.h>
    #include <sstream>
    
    using namespace std;
    
    int StringToNumber(string MyString){
        istringstream converter(MyString);
        int result;
        converter > result;
        return result;
    }
    string EnterOnlyNumber(){
           string numAsString = "";
           char ch = getch();
           while (ch != '\r') { // \r is the enter key
               if (ch >= '0' && ch <= '9') {
                   cout << ch;
                   numAsString += ch;
               }
               ch = getch();
           }
           return numAsString;
           }
    string EnterPassword() {
           string numAsString = "";
           char ch = getch();
           while (ch != '\r') { // \r is the enter key
               cout << '*';
               numAsString += ch;
               ch = getch();
           }
           return numAsString;
    }
    int main(int argc, char *argv[])
    {
        // Just a basic name-netering
        string name;
        cout << "What is your name? ";
        cin >> name;
        cout << "Hello " << name << endl;
        // Now you are asked to enter a number,
        // but the computer allows you to enter anything!
        int x;
        cout << endl;
        cout << "Enter a number, any number! ";
        cin >> x;
        cout << "You chose " << x << endl;
        // This time you can only enter a number.
        cout << endl;
        cout << "This time you'll only be able to enter a number!" << endl;
        cout << "Enter a number, any number! ";
        string entered = EnterOnlyNumbers();
        int num = StringToNumber(entered);
        cout << endl << "You entered " << num << endl;
        // Now enter a password!
        cout << endl;
        cout << "Enter your password! ";
        string password = EnterPassword();
        cout << endl << "Shhh, it's " << password << endl;
        return 0;
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,434

    Re: struggle...

    Quote Originally Posted by dovip View Post
    I am using on Dev C++. However, I couldn't figure out it...because I got few errors.
    And what does this have to do with the topic of this forum, which is Visual C++ Bugs & Fixes??

    Please post in the Non-Visual C++ forum. This forum concerns bugs that are internal to the Microsoft Visual C++ brand of compiler, not general C++ programming bugs (the bugs that are caused by bad programming).

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2012
    Posts
    9

    Re: struggle...

    Quote Originally Posted by Paul McKenzie View Post
    And what does this have to do with the topic of this forum, which is Visual C++ Bugs & Fixes??

    Please post in the Non-Visual C++ forum. This forum concerns bugs that are internal to the Microsoft Visual C++ brand of compiler, not general C++ programming bugs (the bugs that are caused by bad programming).

    Regards,

    Paul McKenzie
    Oh ok. I made mistaken. Thanks.

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,051

    Re: struggle...

    [Moved thread]
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,622

    Re: struggle...

    you have
    Code:
    converter > result;
    It should be
    Code:
    converter >> result;
    Last edited by Philip Nicoletti; December 22nd, 2012 at 04:12 PM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center