program cannot find the directory.

Pages: 12
closed account (LAfSLyTq)
here is basically what my code is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
string c2 = "checkpoint2.txt";
string c3 = "checkpoint3.txt";
string c4 = "checkpoint4.txt";
string c5 = "checkpoint5.txt";
string c6 = "checkpoint6.txt";
string c7 = "checkpoint7.txt";
string c8 = "checkpoint8.txt;
string c9 = "checkpoint.txt";

int main(){
	ofstream text;
	cin>>path;
	text.open(path + c2);
	text<<"2,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c3);
	text<<"3,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c4);
	text<<"4,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c5);
	text<<"5,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c6);
	text<<"6,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c7);
	text<<"7,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c8);
	text<<"8,0,0\n0,0,0\n0,0,0";
	text.close();
	text.open(path + c9);
	text<<"9,0,0\n0,0,0\n0,0,0";
	text.close();
} 


for some reason it will not let me use the directory of
C:\Users\Jeremy\Documents\My Games\

However, C:\Users\Jeremy\Documents\ will work just fine on its own.

help?
That folder does not exists by default in windows 7, did you created first ?
closed account (LAfSLyTq)
yes
Your using cin to get the path so you probably get
C:\Users\Jeremy\Documents\My
as your path. Use getline instead.
Last edited on
closed account (LAfSLyTq)
how do i use getline?
1
2
3
4
5
#include <string>
...
std::string str;
...
getline(std::cin,str);
Last edited on
closed account (LAfSLyTq)
error: no instance of overloaded function "getline" matches the argument list
error: too few arguments in function call
closed account (LAfSLyTq)
nevermind, i found out how to use getline, still doesnt work. i also tried using underscores. doesnt work
Try using fore slashes /
closed account (LAfSLyTq)
already have
closed account (LAfSLyTq)
please help?
I'm surprised this code compiles at all, since most of it is a string. XD
How exactly are you using getline?
closed account (LAfSLyTq)
getline(cin, path);


cin>>path; worked just as good.
Have you output the path with the filename to verify it is correct? Asleep Also have you tried escaping the back slashes?
Edit: my phones predictive text got me.
Last edited on
closed account (LAfSLyTq)
im not understanding you, as ive said before c:\users\jeremy\documents\ worked
closed account (LAfSLyTq)
help
I just ran this simplified version of your code and it works fine using getline, not with >>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string c2 = "checkpoint2.txt";

int main(){
	string path;
	ofstream text;
	//cin>>path;
	getline(cin,path);
	text.open(path + c2);
	text<<"2,0,0\n0,0,0\n0,0,0";
	text.close();
	return 0;
} 


Edit: Run that code, if it doesn't work and you are absolutely sure the path is correct, check the folders permissions.
Last edited on
closed account (LAfSLyTq)
1. im already running the program as admin, and 2. i never said it doesnt work i just said that it doesnt create the files in the directory i want
i never said it doesnt work

Oh? If it works, then aren't we done here?

Here's a line that you should run:
cout << path + c2 << endl;

That's common sense though, people shouldn't have to tell you this.
Last edited on
when you open the file, I saw you use
 
text.open(path + c5);

Normally you should open as C_string. Have you tried that?
Pages: 12