0
我想創建一個獲取用戶輸入到類型字符串數組的程序,但是因爲我不知道用戶要放多少物品在,我要創建數組空的,因爲我知道,所以當我試圖創建一個帶有錯誤出現在任何初始值陣列如何在C++中定義一個沒有大小初始值的數組
LNK2001 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * listOfItems" ([email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@A)
這裏的形象代碼 CODE。
#include "stdafx.h"
#include <iostream>
#include <string>
std::string listOfItems[];
void getInfoToArray()
{
for (int i = 0;; i++)
{
//Get the info of the array.
std::cin >> listOfItems[i];
//Check if the user input is -1.
if (listOfItems[i] == "-1") break;
}
}
int main()
{
getInfoToArray();
return 0;
}
如果有人比試圖創建一個空數組有更好的解決方案,我會很感激。
使用std :: vector的,而不是發表評論。 –
https://i.imgur.com/5r143L6.png – melpomene
謝謝弗拉德,我該如何評價你的回答? – Nomade040