Click here to Skip to main content
16,005,697 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CString to LPCWSTR conversion ??? Pin
Christian Graus2-Jun-05 14:31
protectorChristian Graus2-Jun-05 14:31 
AnswerRe: CString to LPCWSTR conversion ??? Pin
ThatsAlok2-Jun-05 19:13
ThatsAlok2-Jun-05 19:13 
AnswerRe: CString to LPCWSTR conversion ??? Pin
cmk5-Jun-05 12:55
cmk5-Jun-05 12:55 
GeneralOPEN GL Problems Pin
amitmohanty2-Jun-05 13:45
amitmohanty2-Jun-05 13:45 
GeneralEasy char manipulation question Pin
Axonn Echysttas2-Jun-05 12:37
Axonn Echysttas2-Jun-05 12:37 
GeneralRe: Easy char manipulation question Pin
Christian Graus2-Jun-05 12:45
protectorChristian Graus2-Jun-05 12:45 
GeneralRe: Easy char manipulation question Pin
Axonn Echysttas2-Jun-05 12:51
Axonn Echysttas2-Jun-05 12:51 
GeneralRe: Easy char manipulation question Pin
Christian Graus2-Jun-05 12:58
protectorChristian Graus2-Jun-05 12:58 
Axonn Echysttas wrote:
But I don't even know that well the difference between C and C++....

Well, suffice it to say that it looks like you're reading a book on C, which means you're learning a lot of bad habits, if you intend to program C++. malloc and free are C, new and delete are C++. You should never mix them, so the easiest thing is to always use new and delete.

Axonn Echysttas wrote:
a = (LPSTR)cmTime.wHour;

You can't just cast a number to a string. If you must use C functions/want to do things the hard way, then sprintf is what you want, as I said.

Axonn Echysttas wrote:
I'm really a beginner in working with strings but I would really appreciate some help.

The core issues regarding strings:

A string is a pointer, not a single intrinsic type. As such, you need to write memory management code to create and dispose of strings.
You cannot turn something into a string by casting it.
My main beef with the way C++ is taught is that people are taught to do exactly what you're doing, hack around with functions you'll never use again, because you will use CString or ( even better most of the time ) std::string.
Oh, one more - strings are null terminated, so you need a string length of 10 to store a nine character string ( you need room for the null at the end ).

This doesn't even begin to address Unicode strings, etc. I'm just talking about a basic char * here.

Axonn Echysttas wrote:
And even if this is C, I want to know how it's done in C.

Yes, unless what you've written is in a class, everything you're doing is C, as well as being valid C++.

The core answer was in my first post - you need sprintf. I think it's a good thing for you to do it the hard way at some point, just like I think you should write your own list class before using std::list. But it's a tool for learning how stuff works, you won't write production code this way. If I had to do this in the real world, I'd write a SYSTEMTIME inserter for iostreams. But that doesn't mean you're doing anything wrong, you need to walk before you crawl. It's just that I recommend learning C++ first, with the string class, then going back later when you understand the rest to understand what the string class does for you ( because string handling is the major hump in early C++ understanding IMO )


Christian Graus - Microsoft MVP - C++
GeneralRe: Easy char manipulation question Pin
David Crow3-Jun-05 2:54
David Crow3-Jun-05 2:54 
GeneralRe: Easy char manipulation question Pin
Gary R. Wheeler2-Jun-05 13:22
Gary R. Wheeler2-Jun-05 13:22 
GeneralRe: Easy char manipulation question Pin
ThatsAlok2-Jun-05 18:59
ThatsAlok2-Jun-05 18:59 
GeneralRe: Easy char manipulation question Pin
Axonn Echysttas2-Jun-05 21:27
Axonn Echysttas2-Jun-05 21:27 
GeneralSerial Communication using the VT100 Protocol Pin
NCARstudent2-Jun-05 12:24
NCARstudent2-Jun-05 12:24 
GeneralRe: Serial Communication using the VT100 Protocol Pin
Gary R. Wheeler2-Jun-05 13:47
Gary R. Wheeler2-Jun-05 13:47 
GeneralWhere to learn about impersonation Pin
BambooMoon2-Jun-05 12:03
BambooMoon2-Jun-05 12:03 
GeneralRe: Where to learn about impersonation Pin
Blake Miller2-Jun-05 14:17
Blake Miller2-Jun-05 14:17 
Questionhow to resize the systray to fit my clock replacment? Pin
ELY M.2-Jun-05 10:49
ELY M.2-Jun-05 10:49 
Generaltesting path Pin
Ann662-Jun-05 10:44
sussAnn662-Jun-05 10:44 
GeneralRe: testing path Pin
BlackDice2-Jun-05 10:55
BlackDice2-Jun-05 10:55 
GeneralRe: testing path Pin
Blake Miller2-Jun-05 14:22
Blake Miller2-Jun-05 14:22 
GeneralRe: testing path Pin
ThatsAlok2-Jun-05 19:03
ThatsAlok2-Jun-05 19:03 
GeneralPrevent another application's dialog showing Pin
Kany Nguyen2-Jun-05 9:41
Kany Nguyen2-Jun-05 9:41 
GeneralRe: Prevent another application's dialog showing Pin
Tom Archer2-Jun-05 10:06
Tom Archer2-Jun-05 10:06 
GeneralProblem with CTreeCtrl and OnNMRclick Pin
AnTri2-Jun-05 9:12
AnTri2-Jun-05 9:12 
GeneralRe: Problem with CTreeCtrl and OnNMRclick Pin
AnTri2-Jun-05 11:40
AnTri2-Jun-05 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.