hello,
im trying to make something using quotes in a string which is then used by system(d.c_string)
heres the code:

#include <iostream.h>
#include <string>
using namespace std;
int main()
{
    string a,b,c,d;
    a="del C:\\users\\robocop\\desktop\\\"";
    cin >> b;
    c="\"";
    d=a+b+c;
    system(d.c_str());
}

Lets say when running i type 'a b c.txt'
What im trying to get here then is the command

del C:\users\robocop\desktop\"a b c.txt"

But when I run it, it says: "cant find C:\users\robocop\desktop\a"
So apparantly it didnt put the quotes around a b c.txt when string d was used as d.c_str(), because those quotes were for the command line console to read a b c.txt as one filename.

Does anyone know what im doing wrong here? :S

The double quotes have to be around the full path names, not around the filename.

The command string you need to build is probably "del \"C:\users\robocop\desktop\a b c.txt\""

The double quotes have to be around the full path names, not around the filename.

The command string you need to build is probably "del \"C:\users\robocop\desktop\a b c.txt\""

i just tried that:

#include <iostream.h>
#include <string>
using namespace std;
int main()
{
    string a,b,c,d;
    a="del \"C:\\users\\robocop\\desktop\\";
    cin >> b;
    c="\"";
    d=a+b+c;
    cout << d;
    system(d.c_str());    
}

its still not working :(
now it gives me:

cant find C:\users\robocop\desktop\a

the cout i added shows that d contains the following string: del "C:\users\robocop\desktop\a"

What's wrong with using the proper API to remove a file?
Like say

unlink( "C:\\users\\robocop\\desktop\\a b c.txt" );
remove( "C:\\users\\robocop\\desktop\\a b c.txt" );

Neither of which require you to guess how many times you need to escape \" or whatever to get the command interpreter to do what you want.

This article has been dead for over six months. Start a new discussion instead.