const char* str和const char str[]的区别】的更多相关文章

这是我在知乎回答的一个问题. 这个问题是C中的一个深坑,首先说结论: char ** 和 const char ** 是两个不相容(incompatible)的类型,能够理解为不能直接赋值 在C11的6.5.2.2 Function calls中有例如以下内容 Each argument shall have a type such that its value may be assigned to an object with the unqualified version of the ty…
部分内容摘自:https://blog.csdn.net/ranhui_xia/article/details/32696669 The version with const char * will copy data from a read-only location to a variable on the stack. The version with static const char * references the data in the read-only location (no…
  vs2015 LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl printR(class std::basic_ostream<char,struct std::char_traits<char> > &,class QueryResult const &)" (?printR@@YAAAV?$bas…
最近写程序的时候发现这样一个问题 #include<iostream> #include <string.h> using namespace std; void reverse(char *str) { int len=strlen(str); char *p=str; ; while(p<q) { char temp=*p; *p=*q; *q=temp; p++; q--; } } int main() { "; ]="; reverse(n1);…
最近在复习C++,指针这块真的是重难点,很久了也没有去理会,今晚好好总结一下const指针,好久没有写过博客了,记录一下~ const指针的定义: const指针是指针变量的值一经初始化,就不可以改变指向,初始化是必要的.其定义形式如下: type *const 指针名称; 声明指针时,可以在类型前或后使用关键字const,也可在两个位置都使用.例如,下面都是合法的声明,但是含义大不同: const int * pOne;    //指向整形常量 的指针,它指向的值不能修改 int * cons…
把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.string转CString string a=”abc”; CString str=CString(a.c_str()); 或str.format("%s", a.c_str()) 2.int转CString Int a; CString Cstr; Cstr.Format(_T("%d"),a); 3.char 转 CString CString.format("%s&qu…
const 是constant 的缩写,“恒定不变”的意思.被const 修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性.所以很多C++程序设计书籍建议:“Use const whenever you need”. 1.用const 修饰函数的参数 如果参数作输出用,不论它是什么数据类型,也不论它采用“指针传递”还是“引用传递”,都不能加const 修饰,否则该参数将失去输出功能.const 只能修饰输入参数: 如果输入参数采用“指针传递”,那么加const 修饰可以防止意外地…
cin.getline()函数是处理数组字符串的,其原型为cin.getline(char * , int),第一个参数为一个char指针,第二个参数为数组字符串长度. getline(cin,str)函数是处理string类的函数.第二个参数为string类型的变量. #include <iostream> #include <string> using namespace std; const int SIZE=20; int main() { string str; cout…
本文来源于网络 出处:点我 有这样一段代码: #include "stdio.h" char *get_string_1() { char p[] = "hello world!"; return p; } char *get_string_2() { char *p = "hello world!"; return p; } int main() { char *p; p = get_string_1(); printf("get_s…
工程在window下编译没有任何问题, 但是在linux(CentOS6)下编译就老是报错 C++ 编译器已升级到最新版 6.1.0 错误如下: In file included /bits/stl_algobase.h::, /bits/char_traits.h:, /, , : /usr/local/include/c++//bits/stl_pair.h: In instantiation of ‘struct std::pair<const std::__cxx11::basic_st…