Error type char C++

Asked

Viewed 43 times

0

Hi, I’m getting this error when I try to save a character from a txt. error: request for Member ĩc_str' in’d[j]', which is of non-class type ĩchar'113 | fscanf(iFile, "%c", d[j]. c_str());

Below is the code snippet:

int image::paleta(string nome, int height, int width){

int i, j; 
int red,green,blue;
char d[3];
cout << "Arquivo de entrada "<< nome <<endl;
ifstream iFile(nome.c_str());

iFile.ignore(INT_MAX, '\n');

cout << width << " " << height << endl << maxcolor << endl;

for(j = 0; j<height; j++)
{
    for (i = 0; i < width; i++)
    {
        fscanf(iFile, "%c", d[j].c_str());
        if(d[0] == '.'){
            iFile >> red;
            iFile >> green;
            iFile >> blue;
            set(i,j,red,green,blue);
            cout << getred(i,j) << " " << getgreen(i,j) << " " << getblue(i,j) << " ";
        }
  • Here fscanf(iFile, "%c", d[j].c_str()); you made a certain C/C mix++. char d[3]; is an array of characters and not a string C++. Use only d[j], supposing that height < 3.

  • I don’t know if I understand, I don’t use char d[3]? but I need to save characters "." x" or "o"

1 answer

0

I managed to solve using

iFile >> dado[i];

for reading.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.