Re: Beginnerproblem argv splitting in cgi

Discussion in 'C++' started by Mike Wahler, Aug 21, 2003.

  1. Mike Wahler

    Mike Wahler Guest

    Timo Meinger <> wrote in message
    news:bi16pr$ink$02$-online.com...
    >
    > Hi!
    > I am a C++ beginner and need help.
    > Since hours i want to write a c++-cgi which gets 3 params,
    > (1 char and 2 int).
    >
    > Excample-call:
    > htt..../test.cgi?x,123,11
    >
    > Print out the argv of my main-method (with cout << ...)
    > argv[0] = test.cgi
    > argv[1] = x,123,11
    >
    > How can I get the values into this variables?
    > char a = x
    > int b = 123
    > int c = 11
    >
    > thanks for your help!
    > Timo


    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <string>

    int main(int argc, char **argv)
    {
    const char repl(',');
    const char with(' ');

    if(argc > 1)
    {
    std::string s(argv[1]);
    std::replace(s.begin(), s.end(), repl, with);

    std::istringstream iss(s);
    char a(0);
    int b(0);
    int c(0);

    iss >> a >> b >> c;

    std::cout << "a == " << a << '\n'
    << "b == " << b << '\n'
    << "c == " << c << '\n';
    }
    else
    std::cerr << "Need argument\n";

    return 0;
    }

    -Mike
     
    Mike Wahler, Aug 21, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,692
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    6,068
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,708
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    996
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. jab3

    char **argv & char *argv[]

    jab3, Dec 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    718
    Chris Torek
    Dec 8, 2004
Loading...

Share This Page