deprecated conversion from string constant to ‘char*’ #include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } int main() { fuc("hello"); } Linux 环境下当GCC版本比较高时,编译代码可能出现的问题 问题是这样产生的,先看这个函数原型: 1 void someF…
#include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } int main() { fuc("hello"); } Linux 环境下当GCC版本比较高时,编译代码可能出现的问题 问题是这样产生的,先看这个函数原型: void someFunc(char *someStr); 再看这个函数调用: someFunc("I'm a strin…
warning:deprecated conversion from string constant to 'char *' 解决方式 #include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } int main() { fuc("hello"); } Linux 环境下当GCC版本号比較高时,编译代码可能出现的问题. 主要原因是: char * 指…
在C++中, char* p = "abc"; // valid in C, invalid in C++ 会跳出警告:warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 改成下面会通过warning char* p = (char*)"abc"; // OK 或者改成下面: char const *p = "abc"; // OK…
std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 version doesn't work for buf NULL/size 0, so try printing // into a small buffer that avoids the double-rendering and alloca path too... char short_b…
/work/platform_bus_dev_drv/led_dev.c:52: error: expected declaration specifiers or '...' before string constant /work/platform_bus_dev_drv/led_dev.c:52: warning: data definition has no type or storage class /work/platform_bus_dev_drv/led_dev.c:52: wa…
How to convert a std::string to const char* or char*? 1. If you just want to pass a std::string to a function that needs const char* you can use std::string str; const char * c = str.c_str(); If you want to get a writable copy, like char *, you can d…