Hi,
I've written a class which contains a number of doubles which I would
like to extract as a string in the format:
double tab double tab...
I've tried a whole host of ideas but I'm drawing a blank when it comes
to compile time. my most recent attempt is:
string toString(){
string output = ("%d\t%d\t%d\t%d\t%d\t%d\t", pos[0], pos[1],
pos[2], vel[0],
vel[1], vel[2]) ;
return output ;
}
can anyone help? 7 5252 Cl*******@hotmail.com wrote: Hi, I've written a class which contains a number of doubles which I would like to extract as a string in the format: double tab double tab... I've tried a whole host of ideas but I'm drawing a blank when it comes to compile time.
Try std::ostringstream. It works similar to std::cout, except that the
characters are stored in a string instead of going to the screen.
HTH,
Michiel Salters. Cl*******@hotmail.com wrote: Hi, I've written a class which contains a number of doubles which I would like to extract as a string in the format: double tab double tab... I've tried a whole host of ideas but I'm drawing a blank when it comes to compile time. my most recent attempt is:
string toString(){ string output = ("%d\t%d\t%d\t%d\t%d\t%d\t", pos[0], pos[1], pos[2], vel[0], vel[1], vel[2]) ; return output ; }
can anyone help?
As the FAQ indicates
( http://www.parashift.com/c++-faq-lit...html#faq-39.1),
you can use a std::ostringstream:
std::string toString() const
{
std::ostringstream oss;
oss << pos[0] << '\t' << pos[1] /* etc. */;
return oss.str()
}
Cheers! --M Cl*******@hotmail.com schrieb: Hi, I've written a class which contains a number of doubles which I would like to extract as a string in the format: double tab double tab... I've tried a whole host of ideas but I'm drawing a blank when it comes to compile time. my most recent attempt is:
string toString(){ string output = ("%d\t%d\t%d\t%d\t%d\t%d\t", pos[0], pos[1], pos[2], vel[0], vel[1], vel[2]) ; return output ; }
can anyone help?
Use a std::stringstream:
std::string toString()
{
std::ostringstream os;
os << pos[0] << '\t'
<< pos[1] << '\t'
<< pos[2] << '\t'
<< vel[0] << '\t'
<< vel[1] << '\t'
<< vel[2] << '\t';
return os.str();
}
HTH
/S
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Perhaps I'm being remedial, but this doesnt seem to work, it all looked
so simple, but the compiler throwing a hissy fit. my code now is:
std::string toString(){
std::ostringstream os;
os << pos[0] << '\t'
<< pos[1] << '\t'
<< pos[2] << '\t'
<< vel[0] << '\t'
<< vel[1] << '\t'
<< vel[2] << '\t';
return os.str();
} ;
but the compiler says:
In member function `std::string particle::toString()':
testtwo.cc:56: error: aggregate `std::ostringstream os' has incomplete
type and cannot be defined
what's going on??!! Cl*******@hotmail.com wrote: In member function `std::string particle::toString()': testtwo.cc:56: error: aggregate `std::ostringstream os' has incomplete type and cannot be defined
what's going on??!!
Perhaps you neglected to #include the proper header, which in this case
is <sstream>?
that would be it... maybe this is why i shouldn't stray outside of c++
for dummies just yet. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James Fortune |
last post by:
Here is an example of Access creating a single page PDF file. The
text in the textbox is scaled to fit horizontally into a grey box 100
pixels wide that is fontsize pixels high. Clicking the...
|
by: F-13 |
last post by:
I'm working on a BOM in Access 200 from an example downloaded from from
the web. The sample database contains three tables, Assemblies (the
list of items needed to assemble any assembly),...
|
by: Nanda |
last post by:
hi,
I am trying to generate parameters for the updatecommand
at runtime.
this.oleDbDeleteCommand1.CommandText=cmdtext;
this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
|
by: Todd_M |
last post by:
I was wondering what anyone might suggest as "best practice" patterns for
streaming out fixed formatted text files with C#? Let's say we get our data
in a dataset table and we need to iterate over...
|
by: Carlos Lozano |
last post by:
Hi,
What is the right way to create an OCX COM component. The component is
already registerred, but can't create an instance. I am using the reference
to the interop module created.
If I use...
|
by: Raphaël Désalbres |
last post by:
Hello, everybody,
I'm having a problem creating a control...All I want to do is a simple poll
system, so I need to input (trough a ListitemCollection) the values from the
user.
The problem is...
|
by: pshvarts |
last post by:
(I'm new in SOAP)
I get some wsdl file (from apache service ). I tried creating SOAP client
with .NET - trying to add Web Reference and get error like: "Custom tool
error: Unable to import...
|
by: tshad |
last post by:
I am trying to set up an Image authorization where you type in the value
that is in a picture to log on to our site.
I found a program that is supposed to do it, but it doesn't seem to work.
...
|
by: astolpho |
last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output:
...
|
by: chromis |
last post by:
Hi,
I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |