Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

file to a function

Name: Anonymous 2011-09-04 0:43

hey,/prog/ i am trying to figure out how to pass a file onto a function , but my compiler goes ape shit when i run the following code .What am i doing wrong? thanks.
#include <iostream>
#include <fstream>
using namespace std;
float read(ifstream,float,float,float);
int main ()
{
    float a,b,c;
    ifstream file
    file.open("file.txt");
    read(quadratic,a,b,c);
   
return 0;
}

Name: Anonymous 2011-09-04 0:45

op here, sorry function call is read(file,a,b,c);

Name: Anonymous 2011-09-04 1:46

Could you at least read the error messages before posting your stupid problems


#include <iostream>
#include <fstream>
using namespace std;
float read(ifstream,float,float,float);
int main ()
{
    float a,b,c;
    ifstream file
<--- missing semicolon
    file.open("file.txt");
    read(quadratic,a,b,c);
  
return 0;
}

Name: >>3 2011-09-04 1:49

Also, you shouldn't be passing a stream object by-value. Pass it by reference.

float read(ifstream&,float,float,float);

Name: Anonymous 2011-09-04 1:49

that was just an error i made when i was copy and pasting
the complier is giving me errors like this "std::basic<ifstream>std::char traits"

Name: Anonymous 2011-09-04 1:51

thanks anon, it worked! you mind elaborating on what i did wrong?

Name: Anonymous 2011-09-04 1:53

>>6
You didn't understand the language you are trying to program in. Read SICP.

Don't change these.
Name: Email:
Entire Thread Thread List