Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rmearig

macrumors newbie
Original poster
Feb 7, 2011
1
0
so im a student at California Baptist University and this is my first semester of C++. the professor is teaching everything in visual studios and does not know a single thing about the mac at all. i have not run into any problems until now. she wants us to input a file and it doesn't work for me.
this is my code:

// Program Frame2 reads input values that represent the dimensions
// of a print from a file and calculate the amount of wood needed for
// the frame.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream inFile;
inFile.open("Frame.txt");
int side; // Vertical dimension in inches
int top; // Horizontal dimension in inches
int inchesOfWood; // Inches of wood needed
inFile >> side >> top;
cout << "Dimensions are " << top << " and " << side << "." << endl;
inchesOfWood = top + top + side + side;
cout << "You need " << inchesOfWood << " inches of wood." << endl;

return 0;
}

and this is my output:
Dimensions are 0 and 0.
You need 0 inches of wood.

i verified that the file was in the same exact spot as my code and it still doesn't work.

Someone said to delete this and it would work but i have no idea where to find it:
_GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1

any suggestions would be great thank you very much
 
any suggestions would be great thank you very much

See on the top of this page where it says "Code Sharing"? That stands for Promotional Code, not Source Code. You want to ask your question in https://forums.macrumors.com/forums/142/

Can't help you much with your problem but I am quite impressed that one can use >> and << to import data from a file or can concatenate a string. None of this NSFileManager and stringByAppendingString mumbojumbo there is in objective-c, cool. :)

You might want to use the debugger and set a break point in your code to inspect the variables as they are getting used, though.
 
The fact that the code and the file are in the same place does not matter: if you are using the build and run functionality in XCode the cwd is not changed to be the location of the source code. When you compile the code in XCode where is the output executable? Move the file to there and run the executable from the Terminal having used the cd command to change to that location.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.