0

Here is a simple program to output to a text file:

#include <iostream>
#include <fstream>

using namespace std;

int main() {
double myNumber = 42.5;
fstream outfile("test.txt", fstream::out);
outfile << "The answer is almost " << myNumber << endl;
outfile.close();
}

All that ends up being wrote to my text file is, "The answer is almost " and the data is not displayed at all. What am I doing wrong? or could it be a problem with Xcode since I am using that as an IDE.

4

2 回答 2

1

There is no problem with your code. It could be a problem with Xcode.

于 2009-09-04T11:46:30.047 回答
1

I'm not sure what the problem is. Is it that it's never executed or that it's writing to the wrong path. To shed light on this try include unistd.h and insert this snippet.

char* s = getcwd(NULL, 256);
printf("im running and pwd is: %s\n", s);

Inside xcode hit CMD-SHIFT-R to open the console and see if it prints anything.

于 2009-09-04T11:57:17.513 回答