对于 C++ - 我可以将每个添加char到string数组中的每个索引:
string *x=new string[10];
x[0] += "a";
x[0] += "b";
x[0] += "c";
x[1] += "x";
x[1] += "y";
x[1] += "z";
cout << "x[0]=" << x[0] << endl; // would be "abc"
cout << "x[1]=" << x[1] << endl; // would be "xyz"
Run Code Online (Sandbox Code Playgroud)
如何在 C 中执行相同的功能?我有一个buff2指向char数组的指针,并试图char从buf. 当我打印出buff2价值时,我不断得到奇怪的价值。
char buf[255];
char *buff2;
int i=0, count=0;
buff2=(char*)malloc(512*sizeof(char));
while((n = read(fd, buf, sizeof(buf[g]))) > 0){ …Run Code Online (Sandbox Code Playgroud) c ×1