String Vector question

This is a discussion on String Vector question within the C++ Programming forums, part of the General Programming Boards category; I'm new to vectors and I saw some syntax I was not familiar with. Text is a vector. Code: text[i][j] ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    47

    String Vector question

    I'm new to vectors and I saw some syntax I was not familiar with. Text is a vector.

    Code:
    text[i][j]
    It appears this is getting the ith string in the vector and the jth character in that string. Is that correct?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >It appears this is getting the ith string in the vector and the jth character in that string. Is that correct?
    Assuming text is a vector of string, then yes. Although I guess technically, it'd be the (i+1)th string, and (j+1)th character, but the i and j probably start at 0 anyway, so as long as the for-loops begin at 0, it would index properly.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    That is assuming:
    Code:
    #include <string>
    #include <vector>
    .
    .
       std::vector<std::string> text;

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    47
    Thanks for clarifying that. For some reason the CS department at my college does not teach anything on vectors so I'm trying to learn it on my own. I had never come across that syntax but its pretty cool.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >For some reason the CS department at my college does not teach anything on vectors
    That's too bad. With the Standard Template Library (STL) now a part of the C++ standard library, C++ now has a powerful library. There's strings, vectors (which can be used like arrays), and various containers like stacks, queues, deques, a bitset class for bit manipulation, plus algorithms to go along with these. Check out the book recommendations at the top of this forum for some books that teach this modern stuff. And here are a couple of references:
    http://www.cppreference.com
    http://www.sgi.com/tech/stl/

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > Text is a vector.
    A vector of what?
    A vector of chars, your answer is wrong
    A vector of char vectors, you may be onto something
    A vector of std::string, mmmm

    Post more code in context if you want better answers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    47
    Well since the title says "String Vector" I was pretty sure you would understand that its a vector of strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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