samedi 27 janvier 2018

How to assign values to String using vector?

struct Books{

std::string title;
std::string author;
std::string des;
int book_id = 0;
char identifier;

} ;

// book 0
book[0].title = "Programming Fundamentals"; // subscript out of range
book[0].author, "Robert Hanks";
book[0].des, "Programming Basics";
book[0].book_id = 101;
book[0].identifier = 'P';

// Struct Object
std::vector <Books> book;

When ever I try to compile the above code its giving me a subscript out of range error.

Am I doing something wrong?

Thanks.

Aucun commentaire:

Enregistrer un commentaire