std::cout inside of object
-
I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?
int main()
{
CTest test;
test.ListItems();
}CTest::ListItems()
{
CString s(_T("abc"));
std::out << s;
}and the output console show:
01378168
. I have tried several things, but something I am missing. Of course, the app recognize CString.
-
I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?
int main()
{
CTest test;
test.ListItems();
}CTest::ListItems()
{
CString s(_T("abc"));
std::out << s;
}and the output console show:
01378168
. I have tried several things, but something I am missing. Of course, the app recognize CString.
How about
CString s(_T("abc"));
std::out << (LPCTSTR)s; -
I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?
int main()
{
CTest test;
test.ListItems();
}CTest::ListItems()
{
CString s(_T("abc"));
std::out << s;
}and the output console show:
01378168
. I have tried several things, but something I am missing. Of course, the app recognize CString.
_Flaviu wrote:
I have a simple console app.
Is it Unicode? If so, you may have to use
wcout
instead."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I have a simple console app. I instantiate a CTest class. How can I output a console inside of class ?
int main()
{
CTest test;
test.ListItems();
}CTest::ListItems()
{
CString s(_T("abc"));
std::out << s;
}and the output console show:
01378168
. I have tried several things, but something I am missing. Of course, the app recognize CString.
-
You need to use one of the methods of
CString
orCSimpleString
that returns a pointer to the characters. Thecout
function does not understand an MFC object reference. -
Hi, The CStringA class has an operator LPCTSTR which means you should be able to use it with cout. There is also a CString::GetBuffer(). Best Wishes, -David Delaune
Randor wrote:
The CStringA class has an operator LPCTSTR
Just a small clarification: CStringA class has an operator LPCSTR. :laugh:
-
Randor wrote:
The CStringA class has an operator LPCTSTR
Just a small clarification: CStringA class has an operator LPCSTR. :laugh:
Yep, I always disliked the TCHAR hacks. Although I do still find myself using the L and _T macros for string literals. :) Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh: Best Wishes, -David Delaune
-
Yep, I always disliked the TCHAR hacks. Although I do still find myself using the L and _T macros for string literals. :) Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh: Best Wishes, -David Delaune
Randor wrote:
Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh:
I am afraid you remember it wrong (if it was me in the restaurant after MVP summit!) :laugh: I usually drink alcohol if I do not drive nor work. :-O
-
Randor wrote:
Btw, I met you some years ago at one of the restaurants after the mvp summit. I think you were the only guy not drinking alcohol if I remember correctly. :laugh:
I am afraid you remember it wrong (if it was me in the restaurant after MVP summit!) :laugh: I usually drink alcohol if I do not drive nor work. :-O
Ok, it would have been at the Submixer[^] which is at the commons area. I went out of my way to make it there in the evenings just to see some of the people from the online forums. Actually now that I think about it, it was probably Marius Bancila. In my mind I've always had both you guys organized as the "Codeguru mvps". Best Wishes, -David Delaune
-
Ok, it would have been at the Submixer[^] which is at the commons area. I went out of my way to make it there in the evenings just to see some of the people from the online forums. Actually now that I think about it, it was probably Marius Bancila. In my mind I've always had both you guys organized as the "Codeguru mvps". Best Wishes, -David Delaune
Maybe it was marius. Sometimes he refused alcohol. This picture is from 2009: [https://forums.codeguru.com/attachment.php?attachmentid=29815&d=1237155757\](https://forums.codeguru.com/attachment.php?attachmentid=29815&d=1237155757)