vector

This is a discussion on vector within the C++ Programming forums, part of the General Programming Boards category; I have the following defined. How would I define the initial row and col for the puzzleletter? ------------------ typedef std::vector<char> ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    18

    Question vector

    I have the following defined. How would I define the initial row and col for the puzzleletter?
    ------------------

    typedef std::vector<char> PuzzleRow;
    typedef std::vector<PuzzleRow> PuzzleLetters;

    Is the below correct?

    std::vector<PuzzleRow> row = 0;
    std::vector<PuzzleRow> col = 0;

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I think the following will declare a vector of vector of char with number of rows equal to r, the number of columns equal to c and each element initialized to '*'.

    vector<vector<char> > PuzzleLetters(r, vector<char>(c, '*'));

    alternatively here's a way to declare vector of vectors with a given number of rows but indefinite number of columns and nothing initialized:


    vector<vector<char> > PuzzleLetters;
    for(i = 0; i < r; i++)
    {
    PuzzleLetters.pushback(vector<char>());
    }

    To place an 'S' in the first column of the first row you may do several things:

    PuzzleLetter[0][0] = 'S'; //using array notation
    PuzzleLetter.begin().front() = 'S';//using STL notation

    Assuming I haven't screwed up somewhere.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 11:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 06:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 01:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21