Solved

strings in C++

Posted on 2006-10-26
9
203 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.....
0
Comment
Question by:kenhoppe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:NorCal2612
ID: 17815423
Can you try

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

Expert Comment

by:0xC0DEB07
ID: 17816024
You can't do that because system() takes *const* string.
You should use ShellExec() or spawn() instead.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17816030
CString str = "\"C:\\Program Files\\go.exe\"";
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:0xC0DEB07
ID: 17816061
0
 
LVL 6

Expert Comment

by:0xC0DEB07
ID: 17816085
lol ozo is right
please disregard my comments
0
 
LVL 4

Expert Comment

by:Prashant Sabnekar
ID: 17832825
try this
CString str = "C:\\Program\ /Files\\go.exe";
0
 
LVL 1

Expert Comment

by:dreichl
ID: 17836020
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);
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question