[英]cannot convert parameter 1 from 'char' to 'const std::basic_string<_Elem,_Traits,_Ax> &'
I am getting abpve error at line str.append(ch);
我在str.append(ch);
行str.append(ch);
abpve错误str.append(ch);
in below code. 在下面的代码中。
I basically want to append str with each char
'ch'. 我基本上想在每个char
'后面附加str。
If someone know the issue please correct my error. 如果有人知道该问题,请更正我的错误。
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;
}
}
string::append has no member function taking a char
as argument. string :: append没有将char
作为参数的成员函数。 You can append null-terminated char
arrays or other stringS
. 您可以追加以null终止的char
数组或其他stringS
。
You can only append a "sequence" of character to a string. 您只能在字符串后附加一个字符“序列”。 "append" is an operation on two (sequence) vector (take the word vector in a more generic sense) like objects. “追加”是对两个(序列)向量(在更一般的意义上采用词向量)类似对象的操作。
You can do the following: 您可以执行以下操作:
Like the compiler says, there is no member function with the signature 就像编译器所说的那样,没有带签名的成员函数
str.append(ch);
You can use either 您可以使用
str.append(1, ch);
or the simpler 或更简单
str.push_back(ch);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.