arguments - Can't return ifstream data? c++ -


this may simple question, don't understand wrong code. want program read character , return program binary file. don't understand why won't accept variables. here's code:

int ncharf() {     int neww;     myfile.get(neww);     return neww; } 

i checked similar questions, didn't help. missing something?

here's error:

severity code description project file line suppression state error c2228 left of '.get' must have class/struct/union

also, wasn't doing before, it's saying myfile invalid identifier.

the way work replacing "neww" "int", can't return value!

int main() {     return 0; //to stop unwanted execution     char curchar[100000000];     ifstream myfile;     myfile.open("befen.bin", ios::in, ios::binary);     ofstream yourfile("enn.bin", ios::out);     int = 1;     if (myfile.is_open())     {         int evar;         while (!myfile.eof())         {             int snchar[100000000];             snchar[i] = ncharf();             evar = rand() % 5 + 1;             if (evar = 1)             {                 snchar[i] = (snchar[i] + 10);             }             if (evar = 2)             {                 snchar[i] = (snchar[i] + 40);             }             if (evar = 3)             {                 snchar[i] = (snchar[i] * 56);             }             if (evar = 4)             {                 snchar[i] = (snchar[i] / 3);             }             yourfile << snchar[i];             yourfile << evar;             = + 1;         }     }     else     {         cout << "there error opening file";     }     return 0; } 

i added main function. how incorporate you're saying @barmar?

you forgot pass myfile argument.

int ncharf(istream &myfile) {     char neww;     myfile.get(neww);     return (int)neww; } 

also, @barmar commented: the argument .get() must of type char, not int.

if want read int binary file should use istream::read instead:

int ncharf(istream &myfile) {     int neww;     myfile.read((char*)&neww, sizeof(int));     return neww; } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -