Author Topic: vector and iterator For Fred  (Read 2766 times)

0 Members and 1 Guest are viewing this topic.

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 599
  • User-Rate: +11/-8
vector and iterator For Fred
« on: January 23, 2017, 09:03:53 PM »
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: [Select]
#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();
}