首先,这是一个“家庭作业”问题,因此向量库和字符串库是不受限制的。我正在尝试了解 C++ 的基础知识。
我对这段代码的意图是制作和使用一个字符串数组。换句话说,单词列表。
当我运行这段代码时,我得到了一堆废话。
如果有更好的方法来制作 c++ 中的单词列表,我很想听听。
const int cart_length = 50;
const int word_length = 50;
int main()
{
char cart_of_names[cart_length][word_length];
float cart_of_costs[cart_length];
char name[word_length];
cout << "enter the name of the first item: ";
cin >> name;
for(int i=0; i<word_length; i++)
{
cart_of_names[0][i] = name[i];
}
cout << endl;
cout << "that is: ";
for(int x=0; x<word_length; x++)
{
cout << cart_of_names[0][x];
}
cout << endl;
return 0;
}