打印字符串数组元素c ++

时间:2014-02-16 18:26:04

标签: c++

尝试从我的字符串数组中打印元素。标记评论错误的位置。

获取错误:

  1. IntelliSense: no operator "<<" matches these operands operand types are: 
    std::ostream << const std::string
    
  2. error C2679: binary '<<' : no operator found which takes a right-hand operand
    of type 'const std::string' (or there is no acceptable conversion)
    

  3. #include <iostream>
    using namespace std;
    
    int main()
    {
        int day = 5, year = 2015;
    
    
        const string months[13] = { 0, "January", "February", "March", "April", 
                                   "May", "June", "July", "August", "September",
                                  "October", "November", "December" };
    
        cout << months[5] << " " << day << ", " << year << endl;  //the first << is the issue
    }
    

1 个答案:

答案 0 :(得分:3)

你没有#include <string>,你很幸运,在<string>找到了<iostream>的部分内容,因此你可以声明months