UTF-8 locale in Visual C++ 2010 - c++

I am trying to read a UTF-8 text file in Visual C++ 2010 using only the standard library and not Boost or Windows APIs. I define the locale as:
std::locale utf8_locale(std::locale(), new std::codecvt_utf8<wchar_t>);
but this results in the following compiler error:
error C2661: 'std::locale::facet::operator new' : no overloaded function takes 3 arguments
error C2664: 'std::locale::locale(const char *,std::locale::category)' : cannot convert parameter 1 from 'std::locale' to 'const char *'

The error is occures in debug mode when the code is used in the file that micrsoft Visual c++ provided below macro is placed.
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
to get rid of this error the #define new DEBUG_NEW should be commented out or the code should be implemented in another file which does not have the above macro.
This bug for Visual c++ 2010 is mentioned here http://connect.microsoft.com/VisualStudio/feedback/details/683483/mfc-c-fails-to-compile-use-of-codecvt-utf8-in-debug-configuration

FYI, another work around is to just write
std::locale utf8(std::locale(), ::new std::codecvt_utf8<wchar_t>);
That will force the compiler to use the global new, instead of the locale new

Related

PIN 3.0 compilation error because of '__value' symbol

I am porting my tool to PIN 3.0 using Visual c++ 2012 because I now have Windows 10. I followed the porting guide provided here
However, I ran into an error:
error C4890: '__value': use of this keyword requires the command line option: /clr:oldSyntax
When turning this /clr:oldSyntax option on, plus adding RTTI availability (/GR instead of /GR-) as otherwise it is not compatible with /clr:oldSyntax, I get more or less the same issue:
error C2059: syntax error: '__value'
this error is located in the file type_trait.h (header file of the PIN 3.0 Library)
#ifdef _STLP_STATIC_CONST_INIT_BUG
static const bool __value;
#else
static const bool __value = sizeof(__test<_Tp>(0)) == sizeof(__select_types::__t1);
#endif
Is this a common issue, and if so is there any workaround ? Or did I missed something in the porting guide ? I understand that the name __value introduced in this PIN 3.0 header is in conclict.
This is apparently a "bug" in visual c++ as reported here
The solution is to add the following preprocessor definition:
/D__value=_value

C++ GNU GCC with #define out & colliding

I am working with Code::Blocks and C++ GNU GCC and trying to port my Visual Studio Project to GNU GCC.
And while I am trying to compile I get stuck with my define macro from a Defines.h file:
#define out &
And when compiling I get this error:
error: expected unqualified-id before '=' token
On this line:
// Open for output. Default for #c ofstream and fstream.
static const openmode out = _S_out;
In ios_base.h
As I know, that file is a part of a libstd library. Can I disable it? If so, how can I do that?
My library doesn't requiring any std c++, just c library.
There are two main options:
Don't define a macro using the word out.
Declare the macro after you include all of your headers.
But seriously, a macro named out that becomes & is a pretty awful macro. It's going to make it difficult to understand the code very quickly.

Compilation error when using LuaPlus

I found a nice tutorial on how to implement LuaPlus into an C++ Project using Visual Studio 2010.
http://www.zynox.net/luaplus-1-compiling-basic-usage/
But I can't get it to work because of some error messages..
mainproject\main.cpp(51): error C2664: ‘GetCurrentDirectoryW’ : cannot convert parameter 2 from ‘char [260]‘ to ‘LPWSTR’
50. char pPath[ MAX_PATH ];
51. GetCurrentDirectory(MAX_PATH,pPath);
52. strcat_s(pPath,MAX_PATH,"\\test.lua");
I tried to use TCHAR instead of char, but then it says:
no instance of overloaded function “strcat_s” matches the argument list
So for testing purposes I just deleted these three lines and replaced them with a static path:
const char* pPath = "C:\\Users\\fancyBubble\\Documents\\Visual Studio 2010\\Projects\\LuaPlusTutorial\\MainProject\\test.lua";
and now I get:
fatal error LNK1104: cannot open file ‘..\Debug\LUAPlus.lib’
I'm absolutely clueless how to fix this.
I even tried to use the same version of LuaPlus that the tutorial-creator probably used, but the error messages didn't go away.
I don't really know what I did wrong, but the admin uploaded the whole solution:
http://www.zynox.net/?wpfb_dl=3
Using this combined with greatwolf's comment it works great. :)

Log4cplus char* and tstring issue with FileAppender

I have two projects with almost the same configuration in visual studio 2010
One with the console works and gives no trouble with the statement
SharedAppenderPtr myAppender(new FileAppender("myLogFile.log"));
While the other project a dll project gives trouble with the same statement
SharedAppenderPtr myAppender(new FileAppender("myLogFile.log"));
The error message is:
Error 3 error C2664: 'log4cplus::FileAppender::FileAppender(const log4cplus::tstring &,std::ios_base::openmode,bool)' : cannot convert parameter 1 from 'const char [10]' to 'const log4cplus::tstring &'
Any suggestions on how I could resolve this issue ?
Try wrapping the "myLogFile.log" like this: LOG4CPLUS_TEXT("myLogFile.log"). You could also use the _T() macro, since you are on Windows with Visual Studio.
I don't know what type log4cplus::tstring is but assuming it is a typedef for a type similar to std::basic_string<cT> (possibly even std::basic_string<cT> with a type cT other than char) you might try one of these:
SharedAppenderPtr app1(new FileAppender(L"myLogFile.log"));
std::string name("myLogFile.log");
SharedApppenderPtr app2(new FileAppender(log4cplus::tstring(name.begin(), name.end())));

No way to solve this without modifying Microsoft header?

Trying to compile this old VC++ 6.0 program in VC++ 2010. This ATL/WTL stuff is giving me lots of problems. I downloaded and have linked to the latest WTL (as far as I know) wtl71.
I am getting compile errors in atlmisc.h:
atlmisc.h(1159): error C2440: 'return' : cannot convert from 'const char *' to 'TCHAR *'
I've searched the 'net, and the answers that come up call for modifying the stock MS atlmisc.h file!
Am I missing something here? What do I need to do to get this to compile?
Most of the time I've seen that error, it's because I've been trying to build a Unicode application. In a Unicode application, the TCHAR* is a short* or wchar_t* rather than a char*.
I'd suggest checking your project settings and making sure that in the project properties, General > Character Set is set to Use Multi-Byte Character Set.