beginner question on vector<struct>

Discussion in 'C++' started by ali labed, Dec 6, 2005.

  1. ali labed

    ali labed Guest

    Does MS Visual C++ not accept vector of a structure ? (in acceptes
    vector<int>)

    struct str1
    {
    string name;
    int num;
    };

    vector<str1> vec_str( 10 ); // <== rejected

    Thanks.
     
    ali labed, Dec 6, 2005
    #1
    1. Advertisements

  2. ali labed wrote:
    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected


    FAQ 5.8
     
    Victor Bazarov, Dec 7, 2005
    #2
    1. Advertisements

  3. ali labed

    Guest

    ali labed wrote:

    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected


    Which version of Visual C++? What is the error message?

    I put this

    #include <string>
    #include <vector>
    using namespace std;

    above your code and Visual C++ 8 Express compiled it, as did Comeau
    online.

    Gavin Deane
     
    , Dec 7, 2005
    #3
  4. ali labed

    Axter Guest

    ali labed wrote:
    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected
    >
    > Thanks.


    Are you sure you posted the full code?
    If your struct has an explict constructor, but no default constructor,
    then the above would not compile.
    But your above example as is should compile. Please post exact compile
    error you're getting.
     
    Axter, Dec 7, 2005
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    900
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. pmatos
    Replies:
    6
    Views:
    25,493
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,828
    Chris Fogelklou
    Apr 20, 2004
  4. Mark McIntyre

    C beginner: struct inside another struct...

    Mark McIntyre, Apr 21, 2006, in forum: C Programming
    Replies:
    5
    Views:
    884
    Yourko
    Apr 23, 2006
  5. Replies:
    8
    Views:
    2,328
    Csaba
    Feb 18, 2006
  6. Replies:
    11
    Views:
    1,179
    Kai-Uwe Bux
    Jun 27, 2007
  7. Javier
    Replies:
    2
    Views:
    895
    James Kanze
    Sep 4, 2007
  8. Rushikesh Joshi
    Replies:
    0
    Views:
    595
    Rushikesh Joshi
    Jul 10, 2004
Loading...