Irina Costăchescu
Irina Costăchescu

Reputation: 1

Pass string with spaces as system argument c++

If I have a path(string) with spaces, for example "C:\\Users\\Irina\\Desktop\\POO\\PROIECT POO\\my file.docx" and I want to open that file, I use the system command like this

system(path.c_str())

And I get the following error :

'C:\Users\Irina\Desktop\POO\PROIECT' is not recognized as an internal or external command, operable program or batch file.

I would really appreciate some help. Thanks :)

Upvotes: 0

Views: 722

Answers (1)

You need to enclose the string in double quotes:

    system(('"' + path + '"').c_str());

Upvotes: 1

Related Questions