T
thomas
1. about string processing
---input--
30
40 thomas chang
--input--
I want to read 30 to an integer, 40 to an integer, "thomas chang" as a
whole to a string;
I used two method:
---code---
cin>>num; getline(cin, string1, '\n');
---code---
then do some processing to string1, but I found that string1 is null.
---code--
cin>>num; cin>>score; cin>>name; //here "name" is a string
---code--
it also will not work for "name" variable.
How to handle it?
2. about "map".
map<string, int> map1;
I want to use "count_if(map1.begin(), map2.end(), great)" to count the
numbers of values which has a "int" greater than map1["thomas chang"].
So I expect the "great" function to be:
int great(const pair<string, int> &v1, const pair<string, int> &v2){
return v1.second > v2.second;
}
but I don't know how to pass the parameter "v2", can anyone help?
---input--
30
40 thomas chang
--input--
I want to read 30 to an integer, 40 to an integer, "thomas chang" as a
whole to a string;
I used two method:
---code---
cin>>num; getline(cin, string1, '\n');
---code---
then do some processing to string1, but I found that string1 is null.
---code--
cin>>num; cin>>score; cin>>name; //here "name" is a string
---code--
it also will not work for "name" variable.
How to handle it?
2. about "map".
map<string, int> map1;
I want to use "count_if(map1.begin(), map2.end(), great)" to count the
numbers of values which has a "int" greater than map1["thomas chang"].
So I expect the "great" function to be:
int great(const pair<string, int> &v1, const pair<string, int> &v2){
return v1.second > v2.second;
}
but I don't know how to pass the parameter "v2", can anyone help?