小编Eyr*_*ael的帖子

为什么矢量会发生这种情况

我一直在编写代码以将书添加到库中。当我将书添加到库中并尝试显示它时,库中什么都没有存储(显示)

在这里,我将库可以容纳的最大书籍数量设置为
100。int maxbooks = 100; 向量图书馆(maxbooks); 当我删除“(maxbooks)”时,代码工作正常。但是我不明白为什么?

#include <iostream>
#include <vector> 
#include <string>

using namespace std;

//struct model a book 
    struct book {
    string authorname;
    string bookname;
}; //struct ends here 

//function to display number of books in the library
void displayLibrary(vector <book> &cmini_library,int cnum_of_books);

//function to add books to the library;
void add (vector <book> &cminilibrary,book dummylibrary,int &num_of_books);

int main() {
    int option;
    int curr_num_of_books = 0; //current number of books in the library
    int maxbooks = 100; …
Run Code Online (Sandbox Code Playgroud)

c++ vector

0
推荐指数
1
解决办法
79
查看次数

标签 统计

c++ ×1

vector ×1