|
Here's how I'd go about doing it:
ostringstream ss;
ss << "PI = " << 3.14159265;
string s = ss.str();
Includes you'll need:
<string>
<sstream>
Assumes:
using namespace std;
Steve
|
|
|
|
|
Thank you very much Steve. It is really usefull.
|
|
|
|
|
itkid wrote: Is there any API which convert int(int a) to basic string(string b)?
std::basic_string is a template.
You can't convert to it, but only to its instantiations e.g. std::string or std::wstring
That said, I would take a look at boost.orgs lexical cast[^] or format[^].
Free but peer-reviewed code. Some of it will be part of the next version of the C++-Standard.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
C++ Faqs[^]
Nibu thomas
Software Developer
|
|
|
|
|
How can I search for a particular file/ directory in all the subfolders of a given directory?
|
|
|
|
|
|
|
Aryan S wrote: How can I search for a particular file/ directory in all the subfolders of a given directory?
try SearchPath()
|
|
|
|
|
Hi, i have a property sheet which is tabbed and the tabs are stacked
there are 6 tabs which strech across two lines,
however when the property sheet is first called, the lower line of tabs seem to be
hidden, they only appear when i have clicked onto another tab
i have posted an image of what i mean, as its hard to explain [^]
Can any one help
thanks
si
|
|
|
|
|
How are you adding the pages to the sheet?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: How are you adding the pages to the sheet?
like this.... any ideas ??
BOOL CTabSettings::OnInitDialog()
{
CDialog::OnInitDialog();
m_sheet.AddPage(&m_page0);
m_sheet.AddPage(&m_page1);
m_sheet.AddPage(&m_page2);
m_sheet.AddPage(&m_page3);
m_sheet.AddPage(&m_page4);
m_sheet.AddPage(&m_page5);
m_sheet.AddPage(&m_page6);
m_sheet.Create(this, WS_CHILD | WS_VISIBLE , 0);
m_sheet.ModifyStyleEx (0, WS_EX_TRANSPARENT);
m_sheet.ModifyStyle( 0, WS_TABSTOP );
m_sheet.SetActivePage(0);
m_sheet.SetWindowPos( NULL, 0, 0, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
.........
|
|
|
|
|
Can we say that class/objects in C++ implicitly supports state based programmming?
|
|
|
|
|
What do you mean exactly ? Can you be more specific ?
You still can have a kind of 'state machine' in a class if you want to. I don't really understand what you are asking for.
|
|
|
|
|
well let me explain,
Say I have a class
Class SunLight{
public:
bool state;
void set_state(bool state_value)
{
state=state_value;
}
};
Here I am have function which changes the data member value of my class. So in general I am changing the state of my class.
in C language I can do same using procedure programming but where I need to explicly declare and hold/preserve variables and manuipulate by passing those variables to function.I think this extra burden on programmer.
finally Such kind of implementation can ne implemented as shown above in C++ using classes. So can we say that for state based system my class are useful and efficient, hence the argument "C++ classes implicilty supports state based programming".
-- modified at 4:54 Friday 21st April, 2006
|
|
|
|
|
|
My sole intension was to validate the thing I put here...If there is any conceptual missunderstanding , u may please state here.
|
|
|
|
|
You can see things as 'encapsulation' also: it is a little bit the same concept. Each object retains its state (that is not directly accessible for the external world) and you can modify it by the use og public functions.
I think it's the same as what you said.
|
|
|
|
|
i still don't understand the whole thing you expllain/ask for (if ever), but if you use a bool, then your object will have only 2 states : ON/OFF, enabled/disabled, true/false...
so, i'd suggest you (once you"ll need to emulate a much bigger state machine), to use an enum which defines one flag per state...
|
|
|
|
|
... or use the "state design pattern", which can be implemented in any OO language.
|
|
|
|
|
can anybody tell abt the VB's chr() equivalent in VC++?
|
|
|
|
|
Please when asking things like that, explain what the function does. I'm not at all familiar with VB so I needed to check in the MSDN for the function. It looks like this function returns the char associated with an ASCII number, am I right ?
There is no need to call a function in C++, just cast your integer into a char and that will do the trick:
char NewChar = (char)65;
|
|
|
|
|
Thanks for ur help! i tried the same way. But as i am not sure of correctness, i placed here.Thanks once again
|
|
|
|
|
in VC++ there is no need for the conversion...
in vb
Dim MyChar As Char
MyChar = Chr(65) ' Returns "A".
in vc++
char MyChar = 65;
is enough
nave
|
|
|
|
|
Yes, but to avoid a warning because you are converting from int to char (possible loss of data), make the casting explicit:
char MyChar = (char)65;
-- modified at 4:51 Friday 21st April, 2006
|
|
|
|
|