Results 1 to 2 of 2

Thread: Command Line parsing with a win32 app

  1. #1
    RStout
    Guest

    Command Line parsing with a win32 app

    OK I have seen all kinds of messages about parsing a command line switch but I cannot get it to work. I am a green as it comes with msvc. I found that if I use lpCmdLine it will give me the complete switch as a string but I read that was a no no. So how do you parse out the switches. I only need two switches.

    #include "stdafx.h"
    #include <iostream.h>


    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {

    HKEY hRegistryKey;
    char *sBuffer;
    sBuffer = lpCmdLine; What I want here is the first and second switches.
    bla bla bla
    }

    I am so green I don't even understand what to do with the .h and .ccp files.

    Help?

  2. #2
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    Use a split function

    PHP Code:
    #include <vector>
    #include <string>
    using namespace std;

    int split(vector<string>& v, const charschar c)
        {
            
    v.clear();
            while (
    true) {
                const 
    charbegin s;

                while (*
    != && *s) { ++s; }

            
    v.push_back(string(begins));

            if (!*
    s) {
                    break;
                }

                if (!*++
    s) {
                    
    v.push_back("");
                    break;
                }
            }
            return 
    v.size();
        } 
    Usage:

    PHP Code:
    vector <stringbs;
    split(bsSTRING GOES HERE' ');

    //Get values:
    bs[0].c_str();
    bs[1].c_str();
    bs.empty();

    //Destroy 
    VS.NET 2003

    Need to email me?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width