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

Plebeian Tier Question

Name: Anonymous 2012-04-30 19:39

First semester CS major here - I was absent from class once a while back and now that we're referencing the material I missed, I'm a little clueless. I have no friends so I figured I'd ask you guys.

Basically put, I'm having a little trouble how ifstream objects work. Before this segment of code, I've successfully opened a file and assigned it to ifstream variable "infile," but I don't know how I'm supposed to use it.

for (i = 1; i<= 3; i++)
{
    getInputs (infile, l, w);
    a = getArea (l, w);
    displayArea (l, w, a);
}

I'm fine with the functions displayArea and getArea, but this is what I'm working off of with getInputs and I'm a little stumped.

getInputs (ifstream& inputFile, double& length, double& width)
{
    inputFile >> length >> width;
}

I realize this fragment is probably retarded but I'm clueless - I'd appreciate any help you can give me.

Name: Anonymous 2012-04-30 20:40

Thanks for nothing, shitheads. This is my first time on /prog/ and I've been taking programming classes for about two months now - I know it's basic material, but it's just what we've been over in class. I'm not going to grovel or act like a bitch to get some help, I'll just figure it out on my own.

Obviously, getInputs is a void function, and any other miscellaneous retardations I either have no excuse for or chalk up to informality. My basic question is this: in the code fragment

inputFile >> length >> width;

the extraction operator works on the text file referenced by the ifstream object inputFile and assigns value to the variables length and width. And since I called them by reference, they should overwrite the value on their corresponding aliases in the main code, right?

Am I that far off base here? I just want to fucking understand this shit.

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