#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
map<string, string> new_map(int people_count){
map<string, string> newMap;
for (int i = 0; i < people_count; ++i){
string stu_name;
string stu_gender;
cout << "请输入学生名字:";
cin >> stu_name;
cout << "请输入学生性别:";
cin >> stu_gender;
newMap.insert(map<string, string>::value_type (stu_gender, stu_name));
}
return newMap;
}
void output_map(){
int num;
cout << "请输入学生数量:";
cin >> num;
map<string, string> newMap = new_map(num);
for(auto it = newMap.begin(); it != newMap.end(); ++it){
cout << it->first << it->second << endl;
}
}
void output_vector(){
string str;
int num_str;
cout << "请输入字符数量:";
cin >> num_str;
vector<int> vec;
for(int i = 0; i < num_str; ++i){
cout << "请随便输入:";
cin >> str;
vec.push_back(num_str);
}
for(auto it = vec.begin(); it != vec.end(); ++it){
cout << "字符是:";
cout << *it << endl;
}
}
int main(){
output_map();
output_vector();
return 0;
}
就这些函数。
允许转载,请附加作者名字,谢谢!