M
Markus
Hi,
I want to get an integer from the user.
crazy. So I tried something like this:
This program works pretty well. But if I put this code in my main
program the b-array does not get a value.
When I change my code the array does not get a value.
What is the problem with the cin >> before the cin.getline() ?
Best Regards
Markus
I want to get an integer from the user.
If the user inserts a character instead of an int the program goescin >> a;
crazy. So I tried something like this:
int get_value() {
int a;
char b[6];
cout << "Insert a value " << endl;
cin.getline(b, 7, '\n');
a = atoi(b);
cout << "a: " << a << endl;
return 0;
}
This program works pretty well. But if I put this code in my main
program the b-array does not get a value.
When I change my code the array does not get a value.
int get_value() {
int a;
int x;
char b[6];
cout << "Insert a value" << endl;
cin >> x;
cout << "Insert a value " << endl;
cin.getline(b, 7, '\n');
a = atoi(b);
cout << "a: " << a << endl;
return 0;
}
What is the problem with the cin >> before the cin.getline() ?
Best Regards
Markus