#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Marlton, NJ
    Posts
    4
    Rep Power
    0

    std::istringstream question


    I could really use some help with this code. When I output msgType, planID, and groupNumber, the outputs are shifted down (i.e. the first field is not ouput).

    The output should be:
    Message Type is 1
    Plan ID is 2
    Group Number is 3

    The output looks like:
    Message Type is 2
    Plan ID is 3
    Group Number is -1

    The code looks like:
    struct
    {
    NS_TYPE::int32 msgType;
    NS_TYPE::int32 planID;
    NS_TYPE::int32 groupNumber;
    } Status;

    Status.msgType = 1;
    Status.planID = 2;
    Status.groupNumber = 3;

    // Output data to stream
    std::stringstream msgType;
    msgType << Status.msgType;
    std::stringstream planID;
    planID << Status.planID;
    std::stringstream groupNumber;
    groupNumber << Status.groupNumber;

    // Output data to strings
    std::string MsgType;
    planID >> MsgType;
    std::string PlanID;
    planID >> PlanID;
    std::string GroupNumber;
    groupNumber >> GroupNumber;

    std::string messageContents = ("");
    messageContents = "\t" + MsgType + "\t" + PlanID + "\t" GroupNumber ;
    oStream << messageContents << endl;
    oStream.close();

    struct
    {
    NS_TYPE::int32 msgType;
    NS_TYPE::int32 planID;
    NS_TYPE::int32 groupNumber;
    } PlanStatus;

    std::istringstream input_parser(messageContents.c_str());

    input_parser >> PlanStatus.msgType;
    input_parser >> PlanStatus.planID;
    input_parser >> PlanStatus.groupNumber;

    cout << endl << "Message Type is " << PlanStatus.msgType << endl;
    cout << endl << "Plan ID is " << PlanStatus.planID << endl;
    cout << endl << "Plan Status is " << PlanStatus.groupNumber << endl;

    Any help would be much appreciated ...
    Thanks,
    Ron
  2. #2
  3. No Profile Picture
    Dinesh_P_V
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    India
    Posts
    259
    Rep Power
    0
    Change the following

    <<<<<<<<<<<<<<<<<<<
    // Output data to strings
    std::string MsgType;
    planID >> MsgType;
    <<<<<<<<<<<<<<<<<<<


    to
    --------------------------------------
    // Output data to strings
    std::string MsgType;
    msgType >> MsgType;
    --------------------------------------

    -Murugesan
    Dinesh_P_V
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Marlton, NJ
    Posts
    4
    Rep Power
    0

    Thanks for the help!


    Murugesan,

    Thanks much ... I caught the error on Fri. but hadn't posted it yet ... I owe you one.

    Ron

IMN logo majestic logo threadwatch logo seochat tools logo