beginner question on vector<struct>

A

ali labed

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.
 
V

Victor Bazarov

ali said:
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
 
D

deane_gavin

ali said:
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
 
A

Axter

ali said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top