|
You can use stringstream for that, it supports formatting and once you are used to it, it is much better than sprintf (better type safety also). Our great Christian wrote an article about it here[^].
|
|
|
|
|
Here is another suggestion.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hello Team,
I am thinking of a sw which can help the people who does the lot of presentation.
Normally when we beam thru the projector from the laptop, everything on the laptop will be visible to the user. we cant use Alt+Tab while presenting.
Thinking of writing a software, thru with ppl will present their presentation and in background they can browse other think in the pc !
can we send output to VGA card using VC++ /MFC?
Thank you
|
|
|
|
|
Instead of writing software, set the VGA output as a second desktop.
|
|
|
|
|
Hello ,
Thank you for the respose. I am using winxp OS. can i know how to get this second desktop in win Xp?
Thank you
|
|
|
|
|
I have an MDI application with 3 CMFCToolbars. When I resize the main window, these toolbars are wandering around the top of the screen of their own accord for no apparently good reason.
Has anybody got any ideas what's causing this and preferably how to stop it as well?
|
|
|
|
|
An app built from the app wizard doesn't exhibit this behavior.
What are you doing different with your toolbars?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Nothing is intentionally different from the code appwizard creates.
It looks like I'm confusing one of the CMainFrame default handlers somehow, I'm just not quite sure where to start looking to fix it and I was hoping someone else had made a similar mistake and could point me in the right direction.
|
|
|
|
|
Hello everyone,
This is what I found when reading atl/com internal implementation code (e.g. ATLCOM.h), for example in the definition of VARIANT. I show similar code segment below.
I think the purpose of such struct definition is, defining struct and a variable of the type (in this sample type tFoo) altogether, any other benefits of using such type of definition?
(I have such question is because I always use typdef to define a struct type, and then using a separate statement to define a vraible of the type, not merge type definition and variable definition together.)
struct tFoo
{
int abc;
} Foo;
int main()
{
Foo;
return 0;
}
thanks in advance,
George
|
|
|
|
|
It's a pretty old school but perfectly valid way of doing things. You see a lot of this in 'C' code. I expect this gets used mostly where the type, tFoo, is not likely to be used again, it's just a one off definition to define Foo as a single entity. It's a style thing rather than anything technical, there's quite a bit of that on the boundary of C and C++ where backward compatability opens up the syntax for a few of the wierder elements from C.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Hi Matthew!
I think in C++, we can use type tFoo, but if in pure C, we need to redefine using typedef for type tFoo in order to use it, correct?
regards,
George
|
|
|
|
|
I really couldn't say for sure George I'm no C expert having started out with C++.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
No problem, Matthew!
Let us just talk in C++ context.
1.
Whether my understanding is correct -- "I think the purpose of such struct definition is, defining struct and a variable of the type (in this sample type tFoo) altogether"?
2.
Any benefits of using such type of definition?
regards,
George
|
|
|
|
|
As C Pallini said
1. Yes
2. No
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Thanks Matthew!
regards,
George
|
|
|
|
|
George_George wrote: int main(){ Foo; return 0;}
That's strange...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi CPallini,
Please ignore the code in main.
I mean the code outside main.
Let me clarify my question,
1. my question is whether the below understanding is correct?
I think the purpose of such struct definition is, defining struct and a
variable of the type (in this sample type tFoo) altogether
2. any other benefits of using such type of definition?
regards,
George
|
|
|
|
|
George_George wrote: 1. my question is whether the below understanding is correct?
I think the purpose of such struct definition is, defining struct and a
variable of the type (in this sample type tFoo) altogether
Yes.
George_George wrote: 2. any other benefits of using such type of definition?
No.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Cool, CPallini!
regards,
George
|
|
|
|
|
Hi,
I'm trying to read a file which contains lines like "0.14779E+02".
A made a function which return a vector\<float\>.
std::vector\<float\> readData() {
std::vector<float> fResult;
CString dataFile = _T("C:\\d2.txt");
std::ifstream input(dataFile);
if (!input) {
MessageBox(0, L"input file cannot be opened", L"error", MB_OK);
return fResult;
}
std::string c;
float fLesen;
while (!input.eof()) {
std::getline(input, c);
fLesen = atof((const char*)(LPCTSTR)c.c_str());
fResult.push_back(fLesen);
}
input.close();
return fResult;
}</float>
Every time I'm trying to print out the float with something like that:
std::vector\<float\> lines = readData();
for (int i = 0; i < sizeof(lines); i++) {
CString a;
a.Format(_T("%f"), lines[i]);
MessageBox((LPCTSTR)a, L"error", MB_OK);
}
the variable a is emtpy.
What am I doing wrong?
Thanks in advance.
|
|
|
|
|
Opa Knack wrote: the variable a is emtpy.
Have you run this in the debugger to see why?
Opa Knack wrote: for (int i = 0; i < sizeof(lines); i++) {
sizeof gives you the size of an object, not the number of elements in the vector.
Try
for (vector <float>::size_type i = 0; i < lines.size(); i++)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In the debugger I can see that 'lines' has the expected values stored in float format.
It's just that the MessageBoxes are always emtpy.
|
|
|
|
|
Opa Knack wrote: In the debugger I can see that 'lines' has the expected values stored in float format.
That must not be true.
I tested your code like this:
std::vector<float> lines;
lines.push_back(1.00);
lines.push_back(2.00);
lines.push_back(3.00);
for (vector <float>::size_type i = 0; i < lines.size(); i++) {
CString a;
a.Format(_T("%f"), lines[i]);
MessageBox(a, L"error", MB_OK);
}
and it works fine.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all..
I have the string of the following format.
example: http://server/sharanu/inbox/test.jpg
Now i want to get only the string inbox and sharanu..
can anyone help me..
thank you
|
|
|
|
|