Struggle...

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

In function `int StringToNumber(std::string)':
13 no match for 'operator>' in 'converter > result'
In function `int main(int, char**)':
56 undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)

anything fix this?

Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#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;
}
You should be using operator>> on line 13.

The function that you call on line 56 does not have the same name as the function defined on line 16.
hmm. how can I write to be using operator? Like operator >> converter > result;?
Also, I found it that I forget I add "EnterOnlyNumbers" from on line 16. lol
converter >> result;
Ah! it worked. Thank you, Peter87.
Topic archived. No new replies allowed.