无法在C++中打印字符串数组元素

Can't Print string Array Element in C++

本文关键字:打印 字符串 数组元素 C++      更新时间:2023-10-16

每当我尝试运行这个程序时,它都会返回一个错误,说:

没有运算符"<<"与这些操作数匹配

另请注意,程序仅在 getChoice() 函数中遇到此问题; main()似乎工作得很好。

#include <iostream>
using namespace std;
int getChoice(string inChoices[]){
    int numOfChoices = sizeof(inChoices) / sizeof(inChoices[0]);
    cout << inChoices[0] << endl << inChoices[1] << endl;
    return numOfChoices;
}
int main()
{
    string choices[2] = { "Happy Day", "Even Better Day" };
    cout << getChoice(choices) << endl;
    cout << endl << sizeof(choices) / sizeof(choices[0]) << endl;
}

你忘了

#include <string>