I'm not sure if this is possible. Basically, I have a function that will detect the current active user.

string currentUser()
    string user;
    ofstream outf("CurrentUser.dat", ios::trunc);
    system("whoami >> CurrentUser.dat");
    ifstream inf("CurrentUser.dat");
    inf >> user;
    return user;

I have another function which will create a directory in the user's computer. The path will be:
/Users/*ActiveUser*/Library/Application Support.

Now, I have a data file containing only the name of the current active user. How can I insert that into a system command such as:

system("mkdir \"/Users/ActiveUserGoesHere/Library/Application Support\"");

If I read the contents of the data file into a string or other variable, can I insert them into that system command so it uses the string as part of the path?

5 Years
Discussion Span
Last Post by Billy D
string cmd("mkdir \"/Users/" + user + "/Library/Application Support\"");


Worked beautifully; I cannot express my gratitude. One other thing, though. Why do I get a warning for:

string path = "mkdir \"/Users/" + user + "/Library/Application\ Support/System\ Preferences\"";

IDE says: "Lexical or Preprocessor Issue; Unknown escape sequence '\ '"

The code compiles/works fine, but I'm curious as to why there is a warning here

Edited by Billy D: forgot to add something


Anything preceded by a backslash is treated as an escape character. If that character isn't one of the ones the compiler recognizes, that's a Bad Thing(TM). In your case you have '\ ', which isn't recognized. If you want a backslash in the string literal, double it up: '\\'.


Goodness, you're pretty much a genius. Thank you so, so much.

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.