invalid conversion from ‘const char*’ to ‘char’

前端 未结 2 1981
忘掉有多难
忘掉有多难 2020-11-27 08:06

I am trying to replace a certain character in a string with a space using the following code line:

str[i] = \" \";

How can realize this wit

2条回答
  •  盖世英雄少女心
    2020-11-27 08:26

    use single quotes

    str[ i ] = ' ';
    

    In C++, the token " " is a string literal which represents an array of two characters: the value of a space in the character set (eg, the value 32 in ascii) and a zero. On the other hand, the token ' ' represents a single character with the value of a space (usually 32). Note that in C, the token ' ' represents an integer with the value of a space. (In C, sizeof( ' ' ) == sizeof( int ), while in C++, sizeof( ' ' ) == 1.)

提交回复
热议问题