We help IT Professionals succeed at work.

strings in C++

kenhoppe
kenhoppe asked
on
Medium Priority
220 Views
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"";
system(str.c_str());

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

thanks in advance.....
Comment
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.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
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";

Commented:
It must read like:

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

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\"");
system(str);
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.

OR

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.