Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can you help me how to set a path for c++ where i can save a file created in c++
Posted
Comments
[no name] 16-Sep-13 23:20pm    
What is your code for creating the file?
cariz 16-Sep-13 23:48pm    
const bool BLCountryLocalized::openFile(string countryCode)
{
string fileName;
fileName.append(countryCode);
fileName.append(".txt");
if ((aPointer = fopen( fileName.c_str() , "a+" )) == NULL )
return false;
else
return true;
}
[no name] 16-Sep-13 23:55pm    
Very good. All you have to do is prepend the pathname to the filename and that's it.
http://www.cprogramming.com/tutorial/cfileio.html

1 solution

You didn't say what technology you were using for your I/O operations but
- fopen_s()[^] takes directory spec as part of the filename.
- CreateFile()[^] likewise.
- streams interface (varying APIs) all take directory spec.

The only place you can't do this is with the console output and debug/output window.
 
Share this answer
 
Comments
cariz 16-Sep-13 23:01pm    
im using the console for input/output. i want the file to be save in specific location. is their any other way to do it in c++ im doing it with class
H.Brydon 16-Sep-13 23:15pm    
This is pretty basic knowledge. If you can't figure that out, you need somebody local that can teach you with some hands-on training.

Google can come up with coding examples. For fopen_s() for example, Google gives https://www.google.com/#q=c%2B%2B+code+examples+fopen_s
[no name] 16-Sep-13 23:56pm    
It is not clear to me what your last line is saying but anyway I think it is a sufficient answer.
H.Brydon 17-Sep-13 0:11am    
I was trying to say that console output can't (easily) be saved to an external file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900