c++ - 编译时字符串数组错误

标签 c++ string

这是我的示例代码:

#include <iostream>
#include <cstring>
#include <vector>
#include <iterator>
#include "MQmessage.h"

using namespace std;

int main()
{
    // declaring an array to store name/value pair
    struct Property  user_property[15];
    const char* const list[] = {"stateCode","errorCode"};
    const size_t len = sizeof(list) / sizeof(list[0]);
    for (size_t i = 0; i < len; ++i) {
        strcpy(user_property[0].name,list[i]);
    }
    for (size_t i = 0; i < len; ++i) {
        std::cout<<user_property[i]<<endl;
    }
    return 0;
}

我在代码中遇到以下错误:

no match for 'operator<<' in std::cout

谁能告诉我我做错了什么?

最佳答案

我猜你想要 std::cout<<user_property[i].name<<endl ,否则你将不得不重载 << Property 的运营商.

关于c++ - 编译时字符串数组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12794498/

相关文章:

c++ - 有什么方法可以降低求这个矩阵的n次方的时间复杂度吗?

c++ - 保持坐标排序

c++ - std::allocator 是否处理 C++17 中的过度对齐类型?

java - 用另一个 ArrayList 中的随机字符串替换 ArrayList 中的特定字符串

c++ - 如何将 CString 转换为 BYTE?

C++ 跨平台归档操作/显示

c++ - sstream : No such file or directory

php - 截断 UTF-8 字符串以适应 PHP 中给定的字节数

java - 为什么这与 String.java 中的另一个对象检查相等?

MySQL 前导 0 的日期格式