Solved

strings in C++

Posted on 2006-10-26
9
199 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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:prashantsabnekar
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
thread-safe code in c++ 2 72
Replace a tag with sed 2 43
word0 challenge 4 54
C# Error - Add Failed 12 52
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now