C++ 打印Vector、map
2015-03-05 15:40
288 查看
#include "stdafx.h"
#include<vector>
#include<map>
int _tmain(int argc, _TCHAR* argv[])
{
/*string s1("what");
string s2("dog");
if (s1 == s2)
{
cout << "s1 == s2" << endl;
}
else if (s1 < s2)
{
cout << "s1 < s2" << endl;
}
else
{
cout << "s1 > s2" << endl;
}
string s1, s2,s3;
cin >> s1 >> s2;
s3 = s1 + s2;
cout << s3 << endl;
string str, resultStr;
while (cin >> str)
{
resultStr += str + ' ';
cout << resultStr << endl;
}
string str, resultStr;
// char ch;
bool hasPunct = false;
cout << "Enter a string :" << endl;
//cin >> str;
getline(cin,str);
for (string::size_type i = 0; i != str.size();++i)
if (ispunct(str[i]))
{
cout << "Y" << endl;
system("pause");
return -1;
}
else
{
resultStr += str[i];
cout << resultStr << endl;
}*/
//string word;
//vector<int> text;
//for (size_t i = 0; i < 10; i++)
//{
// text.push_back(i);
//}
//for (vector<int>::iterator it = text.begin(); it != text.end(); it++)
//{
// cout << *it << endl;
//}
//for (int i = 0; i < text.size(); i++)
//{
// cout << text[i] << endl;
//}
/*map<int, string> myText;
myText[1] = "Faelan";
myText.insert(make_pair(2, "Faelan2"));
for (map<int,string>::iterator it = myText.begin(); it != myText.end(); it++)
{
cout << it->first << ":" << it->second << endl;
}
cout << myText[2] << endl;
string szRes = myText.find(2)->second;
cout << szRes << endl;*/
struct Faelan
{
int a;
string b;
};
map<int, Faelan> myText;
Faelan value;
value.a = 1;
value.b = "ABC";
myText[1] = value;
cout << myText[1].a << ":" << myText[1].b;
for (map<int, Faelan>::iterator i = myText.begin(); i != myText.end(); i++)
{
if (i->first==1)
{
cout << i->first << "::" << i->second.a << ":" << i->second.b << endl;
}
}
system("pause");
return 0;
}
#include<vector>
#include<map>
int _tmain(int argc, _TCHAR* argv[])
{
/*string s1("what");
string s2("dog");
if (s1 == s2)
{
cout << "s1 == s2" << endl;
}
else if (s1 < s2)
{
cout << "s1 < s2" << endl;
}
else
{
cout << "s1 > s2" << endl;
}
string s1, s2,s3;
cin >> s1 >> s2;
s3 = s1 + s2;
cout << s3 << endl;
string str, resultStr;
while (cin >> str)
{
resultStr += str + ' ';
cout << resultStr << endl;
}
string str, resultStr;
// char ch;
bool hasPunct = false;
cout << "Enter a string :" << endl;
//cin >> str;
getline(cin,str);
for (string::size_type i = 0; i != str.size();++i)
if (ispunct(str[i]))
{
cout << "Y" << endl;
system("pause");
return -1;
}
else
{
resultStr += str[i];
cout << resultStr << endl;
}*/
//string word;
//vector<int> text;
//for (size_t i = 0; i < 10; i++)
//{
// text.push_back(i);
//}
//for (vector<int>::iterator it = text.begin(); it != text.end(); it++)
//{
// cout << *it << endl;
//}
//for (int i = 0; i < text.size(); i++)
//{
// cout << text[i] << endl;
//}
/*map<int, string> myText;
myText[1] = "Faelan";
myText.insert(make_pair(2, "Faelan2"));
for (map<int,string>::iterator it = myText.begin(); it != myText.end(); it++)
{
cout << it->first << ":" << it->second << endl;
}
cout << myText[2] << endl;
string szRes = myText.find(2)->second;
cout << szRes << endl;*/
struct Faelan
{
int a;
string b;
};
map<int, Faelan> myText;
Faelan value;
value.a = 1;
value.b = "ABC";
myText[1] = value;
cout << myText[1].a << ":" << myText[1].b;
for (map<int, Faelan>::iterator i = myText.begin(); i != myText.end(); i++)
{
if (i->first==1)
{
cout << i->first << "::" << i->second.a << ":" << i->second.b << endl;
}
}
system("pause");
return 0;
}
相关文章推荐
- C++ 打印Vector、map
- C++ 标准库 vector list map 基本使用方法 示例程序
- c++ python交互之boost.python 简集之Vector(map)混合使用
- C++ vector 和 map的删除
- c++容器(vector|map)中使用函数指针
- C++中 vector、list、deque、set、map的底层实现
- C++MAP和vector的用法
- C++容器vector和map的正确删除方法
- (c++)vector map multimap set 的使用
- 【语言-C++】C++容器:list、vector、hash、map的区别及使用范围
- C/C++--STL中list,vector,deque,map,set区别、联系和使用场景
- C++ 标准库 vector list map 基本使用方法 示例程序
- C++中防止STL中迭代器失效——map/set等关联容器——vector/list/deque等序列容器—如何防止迭代器失效—即erase()的使用
- C++存储数据结构List、CArray、Vector和Map使用分析
- C++各个容器比较(vector,deque,list,set,map,queue,stack)
- c++ python交互之boost.python 简集之Vector(map)混合使用
- c++容器(vector|map)中使用函数指针
- C++ 标准库 vector list map使用方法
- c++ set map list vector deque区别
- c++ list, vector, map, set 区别与用法比较