无法打印字符串数组元素
Can't Print String Array Element
每当我尝试运行这个程序时,它都会返回一个错误,说:
没有运算符"<<"与这些操作数匹配
另请注意,程序仅在getChoice()
函数中遇到此问题。
#include <iostream>
#include "utilities.h"
using namespace std;
int getChoice(string inChoices[]){
int numOfChoices = sizeof(inChoices) / sizeof(inChoices[0]);
string x = inChoices[0];
string y = inChoices[1];
cout << x << endl << y << endl;
return numOfChoices;
}
int main()
{
string choices[2] = { "Happy Day", "Even Better Day" };
cout << utilities::getChoice(choices) << endl;
cout << endl << sizeof(choices) / sizeof(choices[0]) << endl;
}
您
还需要包含string
标头:
#include <string>
你需要#include <string>
而且您在getChoice()
中对numOfChoices
的计算是错误的,因为参数 inChoices
实际上是"指向字符串的指针"而不是"字符串数组"。
相关文章:
- 数组元素打印的递归方法
- 使用指针初始化 char 数组或字符串 C++
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 为什么使用数组元素查找最大数字的程序不起作用?
- 数组元素更改值?
- 如何访问宏中定义的数组元素
- 将数组元素递增 1
- 如何获取数组中字符串元素的字符数?[C++]
- 使用Stoi()将字符串数组元素转换为C 中的INT
- VS 在打印字符串数组元素 - c++ 时中止
- 打印字符串数组元素 c++
- 无法在C++中打印字符串数组元素
- 无法打印字符串数组元素
- 计算字符串/数组元素的十六进制,然后将其转换为十进制
- 如何将数组(或c字符串)中的元素左移给定数量的索引
- 如何打印字符串C++中的数组元素
- C++字符串长度:数组元素与字形
- 比较字符串数组元素
- 输出一个赋值给c++双精度数组元素的字符串
- 如何访问指针数组中字符串的各个元素