combining diverse data types

M

Miner Jeff

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
 
T

Thomas J. Gritzan

Miner said:
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);
 
M

Miner Jeff

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);

Thanks Thomas, I'll try it.

Jeff
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top