Help with accessing vector variables
Hi,
I'm just learning how to use vectors, read the FAQ on Vector and Deque and some thigns are still blurry. I've got a simple code to put some values into a vector and then read them back. I get a compiler warning when this code runs.
Code:
#include <vector>
#include <string>
#include <iostream.h>
using namespace std;
int main()
{
string C;
int A;
int i;
vector<int> Nums_Vec;
vector<string> Words_Vec;
for (i=0; i<6; i++)
{
A=i;
Nums_Vec.push_back(A);
C="one";
Words_Vec.push_back(C);
}
for (i=0; i<6; i++)
{
printf("%d\t%s\n", Nums_Vec[i], Words_Vec[i].c_str());
}
return 0;
}
And also, can I put a vector inside a class, something like this:
Code:
class FSAD //Fixed/Selectable Analog Data
{
public:
char Name[25];
int nExpected; // size = nExected*2+1
vector<DataLine> DL_Vec;
};
Right now it doesn't recognise the syntax. Error I get:
Code:
h:\code\edfparse3\edfparse3.h(34) : error C2143: syntax error : missing ';' before '<'
h:\code\edfparse3\edfparse3.h(34) : error C2501: 'vector' : missing storage-class or type specifiers
h:\code\edfparse3\edfparse3.h(34) : error C2059: syntax error : '<'
h:\code\edfparse3\edfparse3.h(34) : error C2238: unexpected token(s) preceding ';' ........
Thanks.