Xcode won't accept input from file

For some reason, Xcode won't accept input from a file, whereas Visual C ++ will. When I run this program in xcode, the numberRows and numberCols variables remain 0 (they are initialized to 0 in the main function). When I run it in Visual C ++ they become 30 and 30 (the top line of maze.txt is "30 30" without quotes). Any ideas why this is happening?

void readIn(int &numberRows, int &numberCols, char maze[][100]){

ifstream inData;
inData.open("maze.txt");

if (!inData.is_open()) {
    cout << "Could not open file. Aborting...";
    return;
}

inData >> numberRows >> numberCols;
cout << numberRows << numberCols;

inData.close();

return;

      

}

+2


source to share


2 answers


Something else is wrong. Unfortunately, it's hard to say.

Try flushing the output to make sure you get the error message:



void readIn(int &numberRows, int &numberCols, char maze[][100])
{
    ifstream inData("maze.txt");

    if (!inData) // Check for all errors.
    {
         cerr << "Could not open file. Aborting..." << std::endl;
    }
    else
    {
         // Check that you got here.
         cerr << "File open correctly:" << std::endl;

         // inData >> numberRows >> numberCols;
         // cout << numberRows << numberCols;

         std::string word;
         while(inData >> word)
         {
             std::cout << "GOT:(" << word << ")\n";
         }

         if (!inData) // Check for all errors.
         {
             cerr << "Something went wrong" << std::endl;
         }
    }
}

      

+1


source


Interestingly so I followed the next suggestion from this post http://forums.macrumors.com/showthread.php?t=796818 :



In Xcode 3.2, when creating a new project based on a stdC ++ project, the Target Build Configuration Template for Debug Configuration adds a preprocessor for macros that are incompatible with NKU-4,2: _GLIBCXX_DEBUG = 1 _GLIBXX_DEBUG_PEDANTIC = 1

Destroy them if you want Debug / gcc-4.2 to execute correctly.

0


source







All Articles