fstream file path on mac

my code is:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ofstream jake("\\Users\\Admin\\Desktop\\wut.txt");
	for(int x=0; x<50; x++)test<<"NO U ";
	cout<<"derp\n";
	test.close();
	return 0;
}


I have tried various forms of this, and all result in a file being named "\Users\Admin\Desktop\wut.txt". When I have tried coding on windows, it recognises the file pathway normally, but on XCode, it doesn't.

It obviously isn't supposed to do anything special; I just wanted to see how to create a file. Any knowledge on this would be appreciated.

Thanks.
Such a directory doesn't exist on a Mac. Further, the Mac file separator isn't a backslash.

When coding paths, use the forward slash, which C++ will convert to your platform's proper path delimiter.

When dealing with files in special paths, there are two general rules:

1. The user gave you the path to use

2. Your program knows something about the user's system.

Your path violates both rules: the user did not supply it as a proper path, and the program assumes something false about the user's system.

Hope this helps.
Topic archived. No new replies allowed.