Filestream issues

Edit, part one of my problem was solved, but not part two, and I also have a couple questions about it.

First, how can I set a filepath for saving/loading files?

Second, why was a portion of my code repeating despite not being a loop? (Not expecting a good answer for this, but one exists I'd love to know it.)

Third, why did windows explorer search not find my files? (I included not indexed locations and any other option I could find)

Fourth, is there a way to freeze or capture a portion of output from a console program so I can read the constantly repeating lines?

End of edit.

Hello all,

I am creating a console program in C++ using windows studio express 2013 to make simple text files for another program (specifically it will eventually be a random map maker for HW2, the maps being simple text files)

I have two problems kinda tied together,

First, I have no idea where the files are after being made.

Second, if I just put in a simple name without a filepath, the program works, but without any indication of where the file created can be found, and windows explorer can't find the file with search (looking under "this pc" with all un-indexed locations checked, even inside other files)

One of the tutorials I found said that the name for opening a file can be a file path, however, when I do this, I get a really weird error, where my if statement that checks for success keeps looping to show me an error, despite not being inside a loop*. I also am getting a couple other short lines of output but can't catch what they say because the fast scrolling from repeat.

*Technically the entire function, plus other stuff, is inside a loop, but it should be asking me for input and doing a whole lot of other stuff if it was repeating that loop.

the offending code snippet, by appearance anyway,
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
#include "cMapStream.h"

bool cMapStream::saveMap(){

	string mapName;
	cout << "What would you like to name the map?\n";
	cin >> mapName;
	cout << "Please enter a random seed,\n";
	cin >> rndSeed;
	srand(rndSeed);
	cout << "How big would you like the map to be?\n";
	cin >> mL;
	(int)mL = ((double)mL * 0.75);
	cout << "finished opening questions\n";
 ofstream savefile;// create a stream object named "savefile"
	savefile.open(mapName);// connect stream to a file
	cout << "opened file\n";
	if (!savefile)// check for failure to connect
	{
		err.rep("mapstream", "savemap", 26, "failed to open file");
		// if failure to connect occurs, inform user and exit function
		return 0;
	}//---close if save check
	else
	{//---open else save check
//stuff to do if file open is successful
}//---close else savecheck
savefile.close(); // disconnect ofstream from file
	return 1;

}//-----------------------------end save game 


mapName is a string variable where I input a filename, or file path, at runtime

err.rep is a function to cout an error with the class, function, line, and optionally notes.

return zero should return the program to the main menu, where it should ask me to go again or exit.
Last edited on
Normally, the file should be saved relative to the run location - in your project directory you should have RELEASE ans DEBUG folders in which the compiled binary is placed. The output file should be there as well.
Last edited on
Cool and thanks, but how do I control where it goes?

And why is a part of my program repeating that shouldn't be repeating?

And is there a way to freeze a console program so I can actually read the output?
Bump, edited the opening post with a couple questions.
Topic archived. No new replies allowed.