combining diverse data types

Discussion in 'C++' started by Miner Jeff, Mar 29, 2009.

  1. Miner Jeff

    Miner Jeff Guest

    My program reads a line of data from a text file and executes tests
    based on the data. The tests either pass or fail.

    I'd like to print to the screen a list of only the failed steps after
    all the tests have been executed. For each failed step, I'd like to
    include data items of various types (e.g., int, string, bool, long
    long).

    Is it possible to combine all the diverse data items for each failed
    step into one element of an array? (E.G., converting each of the
    items to a c-string, concatenating these c-strings, then adding the
    resultant c-string as an element to an array.)

    Otherwise, how would I create an array containing mixed data types?

    Thanks,

    Jeff
     
    Miner Jeff, Mar 29, 2009
    #1
    1. Advertising

  2. Miner Jeff schrieb:
    > My program reads a line of data from a text file and executes tests
    > based on the data. The tests either pass or fail.
    >
    > I'd like to print to the screen a list of only the failed steps after
    > all the tests have been executed. For each failed step, I'd like to
    > include data items of various types (e.g., int, string, bool, long
    > long).
    >
    > Is it possible to combine all the diverse data items for each failed
    > step into one element of an array? (E.G., converting each of the
    > items to a c-string, concatenating these c-strings, then adding the
    > resultant c-string as an element to an array.)


    Yes:

    // build message
    std::eek:stringstream ss;
    ss << "some text " << 42 << " whatever else";

    // convert to string
    std::string line = ss.str();

    // insert into vector
    std::vector<std::string> messages;
    messages.push_back(line);

    --
    Thomas
     
    Thomas J. Gritzan, Mar 29, 2009
    #2
    1. Advertising

  3. Miner Jeff

    Miner Jeff Guest

    On Mar 28, 8:05 pm, "Thomas J. Gritzan" <>
    wrote:
    > Miner Jeff schrieb:
    >
    > > My program reads a line of data from a text file and executes tests
    > > based on the data. The tests either pass or fail.

    >
    > > I'd like to print to the screen a list of only the failed steps after
    > > all the tests have been executed. For each failed step, I'd like to
    > > include data items of various types (e.g., int, string, bool, long
    > > long).

    >
    > > Is it possible to combine all the diverse data items for each failed
    > > step into one element of an array?  (E.G., converting each of the
    > > items to a c-string, concatenating these c-strings, then adding the
    > > resultant c-string as an element to an array.)

    >
    > Yes:
    >
    > // build message
    > std::eek:stringstream ss;
    > ss << "some text " << 42 << " whatever else";
    >
    > // convert to string
    > std::string line = ss.str();
    >
    > // insert into vector
    > std::vector<std::string> messages;
    > messages.push_back(line);
    >
    > --
    > Thomas


    Thanks Thomas, I'll try it.

    Jeff
     
    Miner Jeff, Mar 30, 2009
    #3
    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. Frank Fredstone
    Replies:
    1
    Views:
    408
    =?ISO-8859-1?Q?Tobias_Schr=F6er?=
    Sep 19, 2006
  2. ramu
    Replies:
    2
    Views:
    330
    rlblaster
    Feb 20, 2006
  3. girays
    Replies:
    5
    Views:
    361
    girays
    Apr 24, 2008
  4. Gary Roach
    Replies:
    0
    Views:
    114
    Gary Roach
    Sep 1, 2013
  5. Fábio Santos
    Replies:
    0
    Views:
    122
    Fábio Santos
    Sep 4, 2013
Loading...

Share This Page