Balanmoorthi
Balanmoorthi

Reputation: 11

C++ system() could not open .txt file when the path have space

I have the txt file in e:/a b In system() function could not accept the space So what to do My c++ code is

#include <iostream>
#include <conio.h>

using namespace std;
int main() 
{
    system("start e:/a b/test.txt");
}

Upvotes: 0

Views: 924

Answers (2)

Phi
Phi

Reputation: 230

I usually make the start upper case like START and i used it like system("START www.gmail.com"); or you could use system("START *URL or EXE-FILE*"); another way to open it is:

CString str = "http://www.wikipedia.org/";
            CString action = "open";
            ShellExecute(NULL, action, str, NULL, NULL, SW_SHOW);
            getchar();

Upvotes: 0

CrazyCasta
CrazyCasta

Reputation: 28362

What you need is to emulate what you would do on the command line. For instance:

system("start \"e:/a b/test.txt\"");

As an aside, generally one uses a .bat extension for batch files. Not sure how picky start is on the extension, but it helps for understandability.

Upvotes: 2

Related Questions