IT-Consultant: James C. Fuller > Discussion

vector and iterator For Fred

(1/1)

James C. Fuller:
Fred,
  You need to read up on iterators also.
Range based for's are one of my favorite items.
You reduce an exe size by about 100k without including the io functions

James


--- Code: ---#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif


#include <vector>
#include <windows.h>   
#include <tchar.h>
#include <cwctype>
using namespace std;

#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")

void    Pause (void);
int     _tmain (int, _TCHAR**);

void Pause(void)
{
    _tprintf(_T("\n%ls\n"), _T("Press any key to continue..."));
    _getwch();
}

int _tmain (int argc, _TCHAR** argv)
{
    wstring  ws;
    vector<wstring>  wsv;
    wsv.push_back(_T("one"));
    wsv.push_back(_T("two"));
    wsv.push_back(_T("three"));
    wsv.push_back(_T("four"));
    wsv.push_back(_T("five"));
    for (auto it : wsv)
    {
        _tprintf(_T("%ls\n"), it.c_str());
    }
     
    Pause();
}


--- End code ---

Navigation

[0] Message Index

Go to full version