Split string

Hi i am new here I was wondering can someone help me I need to split string like below:

C:\Windows\ File1.exe C:\Windows\File 2.exe

Basicly what I want is two string returned ex

string 1 C:\Windows File1.exe
string 2 C:\Windows\File 2.exe

What i want this for is my little commandline interpter i am trying to make.
I bascily want to make a copy function like what in dos

Hope someone can help or point me in the right place
Last edited on
first question

std::strings? research find() and reverse_find() I believe they are in the string library.

1
2
3
4
5
6

string filename = "C:\Windows\ File1.exe C:\Windows\File 2.exe";
int pos = filename.find(" ");
string string1 = filename.substring(1, pos);
string string2 = filename.substring(pos);


if this is coming into the command line, the argc and *argv[] should break this stuff up for you. For example like this parse which is parsed the main(argc, *argv[]) stuff.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

bool CmdLineOpts::ParseCmdLine(int nArgCnt, char *pArg[]) // these are the args that come from main()
{
    // iterate the list of command line Args.
    bool bSuccess = true;
    int nArgIndex =0;
    string strArg;
    string strError;

    if(nArgCnt > 1)
    {
        while (++nArgIndex < nArgCnt)
        {
            strArg = pArg[nArgIndex];
            if(!strArg.empty())
            {
                  // process the arg.
            }
        }
    }
}
Last edited on
Thanks that just what i needed.
Topic archived. No new replies allowed.