0

For Making long description short see my case:

suppose,

path: "../defult123/test.txt"

my code: ofstream fout("../defult123/test.txt",ios::out);

Here in "defult123", "default" is static but "123" is dynamic .So Basically 

path should be written as: "../default***/test.txt"

So how can i access this dynamic path for writing in test.txt file.

so should be working ??
ofstream fout("../default*/test.txt") 

or,do  i have to list directory fist then check for folder named "default" in sub folder? if so then how do i do that?

please be a help....

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

string concatenation.
If you're saying "...default***/test.txt" is the path, where the user picks
what goes in ***, then you can achieve this with string concatenation. For example :

string startPath = "...//default";
string endPath = "//test.txt";
string pathNumber = "";
string finalPath = "";
cin >> pathNumber;
if(pathNumber != "-1"){
  finalPath = startPath + pathNumber + endPath;
}
else {...}
ofstream file(finalPath.c_str());
//...

Thats the general idea, you don't have to use that much variables.

Edited by firstPerson: n/a

This topic has been dead for over six months. 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.