CString into Bytes

This is a discussion on CString into Bytes within the C++ Programming forums, part of the General Programming Boards category; Hi all, Im quite new to C++ and im trying to convert a CString into a byte - or get ...

  1. #1
    Registered User RocketMan's Avatar
    Join Date
    Dec 2007
    Posts
    28

    CString into Bytes

    Hi all,

    Im quite new to C++ and im trying to convert a CString into a byte - or get my byte out of the CString. I have tried doing it the C way via typecasting and that does not work. I have had a look at msdn and cant find a simlar example.

    Could somebody give me some help.

    Cheers,

    Rocketman.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    19
    You do realize that a CString holds more than one value, right? It's kinda like an array holding x-numbers of bytes. Basicly, you want to convert n*B to just 1*B, without even knowing n. To me, that sounds an awful lot like a hash-function! (I.e. completely irreversible)

    I do realize I might be misinterpreting Your question. When You write "convert a CString into a byte", do you mean "into a byte", or do you mean that each cell should be one byte?
    Last edited by Walle; 01-13-2010 at 03:22 PM.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I haven't used MFC for many years, but I'm pretty sure this should work:
    Code:
    CString str = "Hello World";
    char c = str[0];
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User RocketMan's Avatar
    Join Date
    Dec 2007
    Posts
    28
    Hi,

    Thanks for your input. It seems so easy now!!

    Regards,

    Rocketman

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    CString has LPCSTR overloaded for this as well if my memory serves me right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21