save in a mkdir

Write your question here.So how would i make it to where i save say a txt file in a folder that is created with mkdir
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <direct.h>

int main()
{
	_mkdir("C:/Users/Example");

	return 0;
}.
¿why would mkdir() make any difference?
ifstream file("C:/Users/Example/someText.txt")
thank you

Alright im not sure if I am doing it wrong or if I just have it in the right place any suggestions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <direct.h>
#include <string>
#include <fstream>

using namespace std;


int main()
{
	fstream inout;
	inout.open ("hello.txt", ios::out);
	inout << "Hello how are you";
	inout.close();

	ifstream file("C:/Users/far/Desktop/hello.txt");

	return 0;
}
The unix way of specifying a path is to separate each entry by a forward slash. Windows uses backslash character as separator between files. So you should be doing:

ifstream file("C:\\Users\\far\\Desktop\\hello.txt");

2 slashes because the backslash in c++ is used for escape sequences, so to produce a literal backslash, you have to specify 2 backslashes (So many details...AMG!)

http://www.cplusplus.com/forum/general/126897/#msg687017

In response to this post, the code is updated to adjust to use backslash only when compiled on a windows platform but to use the normal forward slash on other platforms

http://ideone.com/MXB82u
Last edited on
oh alright i see what your talking about i ran that through and changed a few things and it seems to work for the most part thank you again
> Windows uses backslash character as separator between files
forward slashes work too http://en.wikipedia.org/wiki/Path_(computing)

> use backslash only when compiled on a windows platform
just tested using forward slashes with _WIN32 defined. No problem (gcc)


By the way, you probably shouldn't use absolute paths
Topic archived. No new replies allowed.