C++ 无法将参数1从';char';至';常量标准::基本字符串<_元素,特征,最大值>&';

C++ 无法将参数1从';char';至';常量标准::基本字符串<_元素,特征,最大值>&';,c++,string,visual-studio-2008,C++,String,Visual Studio 2008,我在str.append(ch)行得到abpve错误在下面的代码中 我基本上想用每个char'ch'附加str 如果有人知道这个问题,请纠正我的错误 int extract(unsigned char data, char i); // Signature of extract function void decoded(istream& input,ostream& output) { int cnt; int x;

我在
str.append(ch)行得到abpve错误在下面的代码中

我基本上想用每个
char
'ch'附加str

如果有人知道这个问题,请纠正我的错误

int extract(unsigned char data, char i); // Signature of extract function


void decoded(istream& input,ostream& output)
    {   
        int cnt;
        int x;

        input.read((char*)&x,sizeof(x));


        cout<<x;
        cnt=x;
        string str;
        char ch;
        for ( ; ; ) 
        {
            char c;

            input.read((char*)&c,sizeof(char));

            if ( input )
            {
                //read_bit(c,output);
                for (int i=7; i>=0; i--)
                {     
                    if(cnt)
                        {
                        cnt--;
                        ch=(char)(((int)'0')+extract(c, i));

                        str.append(ch);// I am getting error at this line.

                        if(huffmanFindTable[str])
                        {
                            output.write((char*)&(huffmanFindTable[str]),sizeof(char));
                            str.clear();
                        }
                        else
                        {
                        }

                    }
                }
            }
            else
            break;
        }



    }
int-extract(无符号字符数据,字符i);//提取函数的签名
无效解码(istream&输入、ostream&输出)
{   
int-cnt;
int x;
input.read((char*)&x,sizeof(x));
cout没有以
char
为参数的成员函数。您可以附加以null结尾的
char
数组或其他
字符串
没有以
char
为参数的成员函数。您可以附加以null结尾的
char
数组或其他
字符串

您只能附加“附加”是对两个(序列)向量(取更一般意义上的单词向量)类似对象的操作

您可以执行以下操作:

  • str.append(1,ch)
  • str+=ch
  • 只能将字符的“序列”附加到字符串中。“附加”是对两个(序列)向量(更一般意义上的单词向量)类似对象的操作

    您可以执行以下操作:

  • str.append(1,ch)
  • str+=ch

  • 正如编译器所说,没有带有签名的成员函数

    str.append(ch);
    
    你可以用任何一种

    str.append(1, ch);
    
    还是更简单

    str.push_back(ch);
    

    正如编译器所说,没有带有签名的成员函数

    str.append(ch);
    
    你可以用任何一种

    str.append(1, ch);
    
    还是更简单

    str.push_back(ch);
    

    现在我把
    char ch
    转换成
    string ch
    ,它解决了我的问题。上面的转换有什么危害吗?现在我把
    char ch
    转换成
    string ch
    ,它解决了我的问题。上面的转换有什么危害吗,第三个选项对我有效。第一个选项给出错误“str周围的堆栈损坏”,第三个选项对我有效。