Thread: vector

  1. #1
    Registered User
    Join Date
    Jun 2002

    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
    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++)

    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, 08:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 10:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 05:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 12:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM