0

I am writing code that uses string and the code needs to be compiled alongside other projects. Some of these projects are using Unicode and some others using multi byte string.

How can write my code in a way that it can be compiled in both configuration?

For example I know that TCHAR is a macro that expand to suitable char based on configuration. Is there any similar things for string/wstring?

What is the best practise on using string/wstring when portability is important?

mans
  • 17,104
  • 45
  • 172
  • 321
  • 1
    `TCHAR` is terrible nowadays, but take a closer look at what `std::string` really is. – chris Dec 18 '13 at 10:52
  • "How to handel string" - Handel is [something (someone) else](http://en.wikipedia.org/wiki/Georg_Friedrich_H%C3%A4ndel). The word you're looking for is "handle". –  Dec 18 '13 at 10:53
  • @chris: What is the best practice? Should I stick to Unicode? Is it supported everywhere? – mans Dec 18 '13 at 10:53
  • 1
    @mans, There's [this question](http://stackoverflow.com/questions/402283/stdwstring-vs-stdstring?rq=1), there's http://utf8everywhere.org. Look around and you'll find a few differing opinions, but should be able to have some idea at least. – chris Dec 18 '13 at 10:55
  • @chris what is std:sring? How can I read more about what is inside? Can you please elaborate? – mans Dec 18 '13 at 10:56
  • @mans, I was referring to [a reference](http://en.cppreference.com/w/cpp/string/basic_string), specifically the type-definition table, keeping in mind `TCHAR` is one or the other. – chris Dec 18 '13 at 10:57
  • `TCHAR` is a Microsoft-ism. Whatever it does is not portable. – Pete Becker Dec 18 '13 at 14:14

1 Answers1

0

You should use std::wstring to store your strings, then convert the strings to what the libraries that you are using is requesting as needed.

Caesar
  • 9,483
  • 8
  • 40
  • 66