Thread: char to unicode string and back

  1. #1
    Registered User
    Join Date
    Mar 2010

    char to unicode string and back

    I'm trying to translate my DOS data to unicode but in understanding C++ strings I am not too far so I need help. I get message "string is not declared" so I think that here misses some header too.
    I started as shown but any suggestion will be appreciated. Speed is first criteria.

    I read chars as binary (from file) then loop through them to replace certain characters with unicode ones. After every character I compose new stringTO with new values. At the end I should got unicode string stringTO in memory.
    Of course, my example dont work (but it is close

                string stringTO = ' ';
                int o;
                for(o=0;myInputString[o] !='\0';o++)
                    int a=myInputString[o];
                      if (a==172){charTO = 'Č';}
                      if (a==143){charTO = 'Ć';}
                      if (a==230){charTO = 'Š';}
                      if (a==209){charTO = 'Đ';}
                      if (a==166){charTO = 'Ž';}
                      if (a==159){charTO = 'č';}
                      if (a==134){charTO = 'ć';}
                      if (a==231){charTO = 'š';}
                      if (a==208){charTO = 'đ';}
                      if (a==167){charTO = 'ž';}
                   stringTO = stringTO + charTO
             fprintf (fo, "%s\n", stringTO);
    Can this go at shown way?

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    You should use std::string as it is in std namespace. You can define charTO as wchar_t. To access string chars individually you may need to use string.c_str(). You can use documentation to know more about string.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Mar 2010
    Thank you siavoshkc for exploring me a huge possibilityes of C++ language regarding my issue.
    But actually, I better like simplest way of helping.
    Some usable code snippet based on my parameters or so...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with passing back pointer pointed to string
    By whichet in forum C Programming
    Replies: 9
    Last Post: 11-21-2007, 06:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  5. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM
Website Security Test