Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > combining diverse data types

Reply
Thread Tools

combining diverse data types

 
 
Miner Jeff
Guest
Posts: n/a
 
      03-29-2009
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
 
Reply With Quote
 
 
 
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      03-29-2009
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: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
 
Reply With Quote
 
 
 
 
Miner Jeff
Guest
Posts: n/a
 
      03-30-2009
On Mar 28, 8:05*pm, "Thomas J. Gritzan" <(E-Mail Removed)>
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: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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
combining different types into single data structure girays C++ 5 04-24-2008 01:28 PM
FA diverse DVDs and SACD-CDs for sale on Ebay anthony DVD Video 2 10-20-2007 03:06 AM
BT Diverse 4010 doesn't show CID from PSTN callers when connectedthrough VOIP GATE 102 dmitri UK VOIP 7 02-15-2007 04:13 PM
Generics and associative array of keys and diverse objects Frank Fredstone Java 1 09-19-2006 11:42 AM
Ability to use both diverse links SKhan3 Cisco 1 03-15-2005 09:23 AM



Advertisments