Wednesday, April 3, 2013

Push structure into vector in C++

Push structure into vector in C++
#include "stdafx.h"
#include <stdio.h>
#include<iostream>
#include<vector>
using namespace std;
//define struct
struct test{
double r;
double theta;
};
int _tmain(int argc, _TCHAR* argv[])
{
test testStr[9];
for (int i =0;i<9;i++)
{
testStr[i].r = 0;
testStr[i].theta = 0;
}
vector<test> strVect; // define a vector of struct
strVect.push_back(testStr[0]);
strVect.push_back(testStr[1]);
printf("test structure %d\n", strVect[0].r);
getchar();
}
view raw gistfile1.cpp hosted with ❤ by GitHub

No comments:

Post a Comment