Solved

strings in C++

Posted on 2006-10-26
9
200 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 3

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now