0

how could I creat a file at desired folder?

Below is my code and what I want to do is
1)I open the "newfile1.txt"and read the first line(e.g Cat) from this file
2) and then create the Cat.txt at "C:\user\user\Desktop\history"

Currently, I could creat Cat.txt at the folder where my program run but I want to creat file @ "C:\user\user\Desktop\history" instead.

{

ifstream readfile("newfile1.txt);

string str;
getline(readfile,str);
str=str+".txt";
ofstream outfile(str.c_str());
readfile.seekg(iso_base::beg);
outfile<<readfile.rdbuf();

readfile.close();
outfile.close();

}

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by fyp
0

So just add the full path to the filename.

str = "C:\\user\\user\\Desktop\\history\\" + str;
str += ".txt";

thanks,Ancient Dragon.

sorry one more question.

When I create Cat.txt, there is one extra file(which has no file name) has been created too. What did i do wrong in my code?

Edited by fyp: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.