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

Pages: 1-

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 19:55

Cast it to a double and then return EXIT_SUCCESS. Good luck!

Name: Anonymous 2012-04-30 19:55

Where the fuck do these retards come from?

I know it's not /prog/ because nobody could have been browsing for this long and not learn at least something.

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.

Name: Anonymous 2012-04-30 22:46

>>4
I'll just figure it out on my own.
You are a liar.

Name: Anonymous 2012-05-01 0:50

>>4
In case you haven't noticed, /prog/ isn't exactly the fastest board there is. Chances are you're going to need to wait longer than an hour to get a good response.

However, I would be surprised if anybody helped you now after that little tantrum. Now fuck off.

Name: Anonymous 2012-05-01 2:29

Program's done and running as intended. Fuck yourselves with a rake.

Name: Anonymous 2012-05-01 6:26

Ohh god OP. Why the fuck did you have to trigger my huge boner now. I'd love to fuck myself with a rake oooohhhh goooooooooddddddd UHHHHHH

Name: VIPPER 2012-05-01 7:03

OP, try writing it in lisp instead.

Name: Anonymous 2012-05-01 12:05

>>7
I wouldn't like to walk the kilometres of dicks you sucked.

Name: Anonymous 2012-05-01 12:42

[quote]ifstream[/quote]
Stopped reading right there.

Name: Anonymous 2012-05-01 13:13

>>11
[quote]
Ripped my anus out right there.

Name: Anonymous 2012-05-01 13:32

>>4
To get a clue about what the >> operator does in case of ifstream, check the documentation. Since this is C++ you can assume from the beginning that what you see will be absolutely retarded.

ifstream& operator>>(ifstream&, some type here&);

What it does is read from the ifstream, in a type-specific way, into the second argument. The return value is the changed ifstream (which is actually just the same ifstream with some changed state). The reason for the return value is simply for making reading chainable.

So (inputFile >> length) return an ifstream which then has operator>> called on it with `width' as an argument.

By now you should be puking blood

Name: Anonymous 2012-05-01 13:35

>>13
no it maek me turn on boner
i want wqork as program mer because :
i ca n do thing like this:
function VeryGoodporgamram(){
return VeryGooDporograom(LOLRECURSIOOINONA=DSN=(=)
}
Haxxr0e3d!

Name: Anonymous 2012-05-01 15:38

>>14
I feel rather vindicated having my contribution to /prog/ being acknowledged by the suss himself.

Name: bampu pantsu 2012-05-29 4:42

bampu pantsu

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