2014-02-09 77 views
-3

每當我試着運行這個程序,它會返回一個錯誤說:無法打印字符串數組元素在C++

沒有運營商「< <」這些操作數

還要注意的是,相匹配程序僅在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; 
} 
+5

你問爲什麼完全一樣的問題,兩次一小時之內? http://stackoverflow.com/questions/21656386/cant-print-string-array-element – neverhoodboy

回答