Thread: Help with accessing vector variables

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    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.
    Last edited by earth_angel; 06-28-2005 at 07:56 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector : accessing values
    By rahulsk1947 in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2009, 09:26 PM
  2. accessing a variable from another method
    By larne in forum C++ Programming
    Replies: 14
    Last Post: 01-16-2009, 04:24 PM
  3. Problems accessing logged on user via System.Security
    By conor20_ie in forum C# Programming
    Replies: 5
    Last Post: 11-16-2007, 07:52 AM
  4. accessing a struct with ->
    By Anddos in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2006, 03:28 PM
  5. accessing documents in a MDI app
    By Tesita in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2001, 06:11 PM