CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    49

    [RESOLVED] vector question

    Hello,

    I have the following code below which crashes:

    Code:
    ifstream file("filename.txt");
    vector<vector<unsigned char> > maxvec; 
    maxvec.resize(10*1024);
    for(unsigned int i = 0;  i < 10; i++) 
    {
       for(unsigned int j = 0; j < 1024; j++)
       {
           int temp; 
           file >> temp;
           maxvec[i][j] = temp;
       }
    }
    I guess it does not like how I assign to the vector. What is the correct way to do this?

    Thanks!
    Alex

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: vector question

    Code:
    maxvec.resize(10*1024);
    resizes the outer vector to have 10k empty vectors of unsigned chars.

    use
    Code:
    maxvec.resize(10, vector<unsigned char>(1024));
    Kurt

  3. #3
    Join Date
    Jan 2012
    Posts
    49

    Re: vector question

    Thanks Zuk!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured