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

标签 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)
    

#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
}

最佳答案

你没有 #include <string> , 你很幸运 <string> 的某些部分被发现于 <iostream>这样你就可以声明 months .

关于c++ - 打印字符串数组元素c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21815508/

相关文章:

c++ - 如何构造具有构造函数参数的对象 vector ?

c++ - 使用 boost 正则表达式提取所有破折号分隔的数字

c++ - MinGW 无法编译,错误 1

c++ - c++中如何实时显示

c++ - Bazel Link .so 库位于一个完全不同的、非常远程的文件夹中

c++ - 共享库 (c/c++) 中的 pstack。损坏的共享库

c++ - C++中exit和kill的区别

c++ - 什么规则支配参数默认赋值?

c++ - 尝试动态内存分配 C++

c++ - VTKPNGWriter 打印出黑色图像?