I am getting abpve error at line str.append(ch);
in below code.
I basically want to append str with each char
'ch'.
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. You can append null-terminated char
arrays or other 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.