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;
ofstream outfile(str.c_str());



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 6 Years Ago by fyp: n/a

This question has already been answered. Start a new discussion instead.