c-strings

    -1热度

    4回答

    所以...... 当我去: cout<<stringName<<endl; 我得到: NT 但是,当我去: cout<<stringName.c_str()<<endl; 我得到: NTNT 为什么?

    1热度

    7回答

    在C/C++的一些人使用C风格的字符串,如: char *str = "This is a c-styled string"; 我的问题是这是安全的?我看到它的方式是他们创建了一个char指针,它指向一个常量字符数组的第一个字母,但不能用其他的东西,例如另一个变量覆盖内存中char数组的一部分?从而导致str逻辑无效?

    18热度

    18回答

    现在有没有什么好的理由在C++中使用C字符串?我的教科书在某些时候在例子中使用它们,我真的觉得使用std :: string会更容易。

    3热度

    5回答

    我的代码段错误,我不知道为什么。 1 #include <stdio.h> 2 3 void overwrite(char str[], char x) { 4 int i; 5 for (i = 0; str[i] != '\0'; i++) 6 str[i] = x; 7 } 8 9 int main(void) { 10 char *s = "abcde"; 11 ch

    6热度

    4回答

    当通过使用recv套接字接收数据,我注意到,具有: char buffer[4]; memset(buffer, 0, 4); recv(socket, buffer, 4, 0); 我接收 mesgx “mesg”就是我发送的,附加了一些随机字符。 如果我使用 char * method = (char *) malloc(4); memset(buffer, 0, 4);

    19热度

    3回答

    我看到使用这种模式来连接到在一些代码字符串我工作: sprintf(buffer, "%s <input type='file' name='%s' />\r\n", buffer, id); sprintf(buffer, "%s</td>", buffer); 和我相当肯定它不是安全C.你会发现buffer既是输出和第一个输入。 除了很明显的缓冲区溢出的可能性,我相信不能保证缓冲区不会在