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....

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.