We help IT Professionals succeed at work.

strings in C++

kenhoppe asked
Medium Priority
Last Modified: 2011-09-20
Hello ,

I am using a C++ command like this:  system("\"C:\\Program Files\\go.exe"");

It works fine and skips the space in the folder called "Program Files".

Now I would like to assign a CString variable such as:

CString str = "C:\\Progam Files\\go.exe"";

How can I use the \" " switch to encapsulate the string to accept the space in "Program Files"

thanks in advance.....
Watch Question

Can you try

CString str = "C:\\Program\ Files\\go.exe";
You can't do that because system() takes *const* string.
You should use ShellExec() or spawn() instead.
Most Valuable Expert 2014
Top Expert 2015
CString str = "\"C:\\Program Files\\go.exe\"";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
lol ozo is right
please disregard my comments
try this
CString str = "C:\\Program\ /Files\\go.exe";

It must read like:

CString str = "\"C:\\Program Files\\go.exe\"";

If you'd like to be able to compile it in Unicode mode, it has to look like the following:

CString str = _T("\"C:\\Program Files\\go.exe\"");
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.