http://www.ohchr.org。 你gged的阵列将是一个包含特征阵列的阵列。 每一点人通常使用4tes(在32台轨道机上),但更正确的是<条码>(char*),因此,你应使用<条码>小范围(3*)代码>。
And then record[i] = (char*)malloc((arrsize[i]+1) * sizeof(char))
, because a string is a char*
and a character is a char
, and because each C-style string is conventionally terminated with a
character to indicate its length. You could do without it, but it would be harder to use for instance:
strcpy(record[0], name);
sprintf(record[1], "%0.2f", mark);
sprintf(record[2], "%d", id);
页: 1 页: 1 缩略语
As regards writing all this to a file, if the file is binary why put everything in as strings in the first place?
Assuming you do, you could use something like:
ofstream f("myfile",ios_base::out|ios_base::binary);
for (int i=0; i<3; i++)
f.write(record[i], arrsize[i]);
f.close();
话虽如此,我还是提出安德斯的想法。 如果你使用STL病媒和扼杀物,那么你就不得不处理令人厌恶的记忆分配问题,你的代码可能也会比较清洁。