C2440: '=': cannot convert from 'const char [9]' to 'char*'

前端 未结 2 1692
面向向阳花
面向向阳花 2021-01-03 13:10

I am working on a Qt5 project written in C++. Building the project gives an error:

C2440: \'=\': cannot convert from \'const char [9]\' to \'char*\'<

2条回答
  •  一生所求
    2021-01-03 13:41

    In C++, in contrast to C, string literals are const. So any pointer to such a string literal must be const, too:

    const char* port_name = "\\\\.\\COM4";  // OK
    // char* port_name = "\\\\.\\COM4";  // Not OK
    

提交回复
热议问题