Thread: CString into Bytes

  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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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 04: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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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, 01: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