program cannot find the directory.

Pages: 12
Jun 3, 2012 at 4:36pm
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?
Jun 3, 2012 at 4:47pm
That folder does not exists by default in windows 7, did you created first ?
Jun 3, 2012 at 4:53pm
closed account (LAfSLyTq)
yes
Jun 3, 2012 at 4:54pm
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 Jun 3, 2012 at 4:55pm
Jun 3, 2012 at 5:02pm
closed account (LAfSLyTq)
how do i use getline?
Jun 3, 2012 at 5:06pm
1
2
3
4
5
#include <string>
...
std::string str;
...
getline(std::cin,str);
Last edited on Jun 3, 2012 at 5:09pm
Jun 3, 2012 at 5:10pm
closed account (LAfSLyTq)
error: no instance of overloaded function "getline" matches the argument list
error: too few arguments in function call
Jun 3, 2012 at 5:27pm
closed account (LAfSLyTq)
nevermind, i found out how to use getline, still doesnt work. i also tried using underscores. doesnt work
Jun 3, 2012 at 6:24pm
Try using fore slashes /
Jun 3, 2012 at 6:36pm
closed account (LAfSLyTq)
already have
Jun 3, 2012 at 6:54pm
closed account (LAfSLyTq)
please help?
Jun 3, 2012 at 7:11pm
I'm surprised this code compiles at all, since most of it is a string. XD
How exactly are you using getline?
Jun 3, 2012 at 7:12pm
closed account (LAfSLyTq)
getline(cin, path);


cin>>path; worked just as good.
Jun 3, 2012 at 7:40pm
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 Jun 3, 2012 at 8:31pm
Jun 3, 2012 at 7:54pm
closed account (LAfSLyTq)
im not understanding you, as ive said before c:\users\jeremy\documents\ worked
Jun 4, 2012 at 3:40am
closed account (LAfSLyTq)
help
Jun 4, 2012 at 4:06am
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 Jun 4, 2012 at 4:15am
Jun 6, 2012 at 5:01pm
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
Jun 6, 2012 at 5:14pm
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 Jun 6, 2012 at 5:18pm
Jun 6, 2012 at 5:54pm
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