Thread: extracting parameters

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    77

    extracting parameters

    I'm new to C++ and would like some help on how I can extract more than one parameter from a string. I have an example of a function that will receive the string. The string contains two parameters and I don't know how to pull off the second parameter. Thanks in Advance.
    JK


    Code:
    void Message_Received(std::istream& args)
    {
        unsigned msg;
    
        // Pull off  the first param in the string
        args >> msg;
    
       // Pull off the second param in the string
       ????
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    If it's another unsigned value, for instance, you simply repeat the extraction from the stream like you did for the first parameter:

    Code:
    void Message_Received(std::istream& args)
    {
        unsigned msg, msg2;
    
        // Pull off  the first param in the stream
        args >> msg;
    
        // Pull off the second param in the stream
        args >> msg2;
    
        ...
    
    }
    Or you could just put everything on one line:

    Code:
    void Message_Received(std::istream& args)
    {
        unsigned msg, msg2;
    
        // Pull off the params from the stream
        args >> msg >> msg2;
    
        ...
    
    }
    [edit]Be careful you don't confuse yourself over strings vs streams, they are different things and what you are talking about here are the latter.[/edit]
    Last edited by hk_mp5kpdw; 12-15-2004 at 12:22 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    Thanks so much for your help and clarification on strings vs streams. I was able to implement what you said and it works!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parameters quick Question
    By lifeis2evil in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2007, 11:12 PM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 11:46 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. command-line parameters.
    By Tombear in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 08:40 AM