您的位置:首页 > 编程语言 > C语言/C++

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ iterator map vector