开发者

XCode will not take input from a file

For some reason, Xcode will not take input from a file, while Visual C++ will. When I run this program in xcode, the variables numberRows and numberCols stay 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 the 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;

}


There is something else wrong.
Unfortunately it is hard to tell.

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;
         }
    }
}


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

Under Xcode 3.2 when creating a new project based on stdc++ project template the target build settings for Debug configuration adds preprocessor macros which are incompatible with gcc-4.2: _GLIBCXX_DEBUG=1 _GLIBXX_DEBUG_PEDANTIC=1

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜