-4
char* rec1= "[email protected]";
char* rec2= "[email protected]";
char** rec ;
我需要char** rec
点rec1
和rec2
,我应该能够使用rec[0]
和rec[1]
访问从REC的rec1
和rec2
元素。如何使用双指针创建指针数组?
如何实现它?
char* rec1= "[email protected]";
char* rec2= "[email protected]";
char** rec ;
我需要char** rec
点rec1
和rec2
,我应该能够使用rec[0]
和rec[1]
访问从REC的rec1
和rec2
元素。如何使用双指针创建指针数组?
如何实现它?
这是你在找什么。
const char *rec1 = "[email protected]";
const char *rec2 = "[email protected]";
const char *rec[] = {rec1, rec2};
std::cout << rec[1];
"[email protected]"
自身是const char[16]
类型的衰减到const char *
的。请注意,不应将其分配给char *
,因为这些字符是只读字符。
const char *rec[]
是const char *
的数组类型。另外{rec1, rec2}
是数组类型的初始值设定项。
'char * rec1 =“[email protected]”;'在今天的C++中是非法的。你需要一个'const' – WhiZTiM
@WhiZTiM - 遗憾的是,你需要编译成相当于迂腐模式的模式才能实际标记。 – StoryTeller
尝试'std :: vector rec = {“[email protected]”,“[email protected]”};'。 –
nwp