向字符串数组中的元素添加数字值
Adding number values to elements in a string array
所以我的第一堂C++课已经 2 周了,我无可救药地坚持我目前的作业。我必须创建一个世界问题列表,并让用户按重要性顺序排列它们。
现在我正在尝试分配数字值,以便用户可以通过键入 1-5 来组织它们来轻松调用它们。我写的代码不起作用,我只是想看看我是否错过了什么。
int main()
{
string topics[5]{"World Hunger", "Government Oppression", "Genocide", "Disease", "Poor Education"};
int responses[2][5] = {{1,2,3,4,5},{1,2,3,4,5}};
topics[5] = responses[5];
return 0;
}
错误:从"int*"到"char"的转换无效
for(int i=0; i<5; ++i) {
std::cout << i+1 << ". " << topics[i] << std::endl;
}
std::cin >> userChoice;
if(userChoice == topics[0] || userChoice == "1") {
//etc
} else if(userChoice == topics[1] || userChoice == "2") {
//etc
} else if(/*etc etc etc*/) { //....
相关文章:
- 我需要知道如何在 c++ 中使用增量值添加到一定数字
- 将随机生成的数字添加到数组 + 对这些数组求平均值
- 在不添加进位的情况下添加数字的C++程序
- 将两个数字添加为链表
- C++:添加到输出中的不需要的数字
- 如何非常快速地将数字添加到 Vector 中的一系列元素中
- 如何在 c++ 中添加两个大的双精度数字
- 字符串添加数字 C++
- Arduino代码无法正确添加数字
- 如何从 while 循环中添加数字
- 在我的输出之前,我该如何添加数字
- C 如何结束一个段循环,该循环添加数字而不使用数字作为触发器来结束循环
- 无法理解为什么在添加数字后在末尾添加零
- C++输入文件添加数字
- 如何创建添加数字的模板函数
- 向字符串数组中的元素添加数字值
- 重载运算符>>并向字符串添加数字
- 如何在矩阵中添加数字以产生最小结果
- 在fstream中添加数字(c++)
- g++ -D选项添加数字1