Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File io how to do something 1

Status
Not open for further replies.

Sudoku

Programmer
Jun 25, 2006
5
CA
I atempted to make a directory for files. To acesses the files I tried to do this:
Code:
ifstream fin(sName);
The variable sName is the name of the file + .txt. This does not work. I not certain if this is even the right direction. Any help or ideas would be apreciated
 
To create a new directory use (non-standard) library function _mkdir from <direct.h>:
Code:
if (_mkdir("D:\\Moo\\Boo"))
{
   // returns non-zero on error
}
Well, a new directory is empty (no files).
Can you explain your problem with ifstream? Where is a path to your new directory in sName?
This does not work - what?..
 
If the file isn't in the same directory as your .exe, you need to include the path + filename.
Ex.
Code:
string sName( "C:/temp/filename.txt" );
 
Oh sorry the directory will be with the .exe. The point of the variable as the file name is to allow the user to name their files.
 
Does the file exist before you try to open it?
Is the file already opened by another program?
Do you have sufficient permissions to read the file?
 
If sname is a C++ string, you must use:
Code:
ifstream fin(sName.c_str());
If it is a character array, make sure you are concatenating the ".txt" part properly with strcat, or switch to C++ strings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top