std::string corruption in Visual Studio 2012 - c++

I have problems with viewing strings in my debug VS2012 project. For some reason, either the string is not readable at all - VS reports '<error string not readable>' - or the first four characters of the strings are always cut. Even so on constant strings. What could cause this?

Related

Printing ASCII code in C ++ (Visual studio not recognizing encoding)

I'm trying to make a xy program which prints ASCII art in the console with chracters such as ⣿, when running the program just prints question marks (?). I understand that its either because of me using the wrong encoding or Microsoft Visual Studio not having the dictionary of these ASCII Characters.
If you have any idea on how to either change encoding or fixing the isue ,it would be much appreciated
Possible solutions:
Try to change the source file encoding to UTF-8 without signature
or UTF-8 with signature.
Try to use wchar_t literal, i.e. std::wcout << L"Your String";.
Learn more:
how to change source file encoding in csharp project (visual studio / msbuild machine)? (Also applies to C++)
What does the 'L' in front a string mean in C++?
There is not a problem with your code but rather a problem with the console that shows your output. It does not show unicode character correctly. In order for it to show these characters correctly it need to recognize unicode and use a font that actually have those characters. To verify this, simple open a cmd window and copy/paste the character into it and see what heppens.

Not visible polish characters in game / AST.dll

Gothic II Returning 2.0 / Visual Studio 2015
I'm trying to translate from Russia to Polish few lines of an AST.dll file. I have visual studio 2015, and project of it. I found lines with russian Text and I translated this into polish, with polish characters like L with line Ł but in game they look like strange symbols.
I tried to save this part of the script (with lines I translated) ConstText.cpp using encoding with UNICODE (UTF-8), and replace this with original script it changed a Little cause I got diffrent types of symbols, but this still isn't polish characters.
1>ConstText.cpp(95): warning C4566: character represented by universal-character-name '\u00F3' cannot be represented in the current code page (1251)
In my opinion i should Save this ConstText.cpp with specific encoding but i don't know what Type of encoding.

Convert old Visual Studio C++ project from multibyte character set

I would like to transfer an old C++ MFC project from Visual Studio 2005 to a newer version. The project uses a multibyte character set that I know is no longer supported in the current Visual Studio. The first step should therefore be to make the project independent of the character set. A colleague at work told me that I can do this if I put a macro _T() around each text.
Unfortunately, the project contains a lot of static text and adding the macros should take weeks.
Is there no other way?
There is no other way unfortunately. You can try to automate text editing with regex or some text editor like sed.
But personally I would prefer to check all the code manually that no multibyte char-related code is left: use _tcslen instead of strlen, _TCHAR instead of char, etc.
Other variant to consider is to make code explicitly use widechars: wcslen instead of strlen, wchar_t instead of char, L"some string" instead of _T("some string"), etc.
UPD: also I found some good news "The deprecation warning [MFC support for MBCS deprecated] has been removed from MFC in VC2017 and we will continue to provide MBCS support in future releases." (https://blogs.msdn.microsoft.com/vcblog/2013/07/08/mfc-support-for-mbcs-deprecated-in-visual-studio-2013/), so probably you can just left it as it is.

Visual Studio force UTF-8 with no signature file encoding

I'm using Qt5 along with Visual Studio 2012 and recently wrote a logger class, which basically redirect string streams to the file. The other day I realised that there is no "special" characters support (eg. polish, german, russian).
qDebug() << "Special characters: ąężźćłóĄĘŻĆŁÓ";
Is producing the following output:
Special characters: �꿟����ʯƣ�
I have tried multiple Unicode settings listen in File -> Advanced Save Options.
However, there is no option to save the file without the BOM signature and I think that might be the issue, since when I change the file encoding through the Notepad++ to UTF-8 (without BOM), then compile, everything is working fine... unfortunately until I make any changes in the Visual Studio.
I have also tried setting compiler encoding to Unicode:
Is there any solution for Visual Studio to change the encoding to UTF-8 without BOM signature?
Code snippet which writes to file:
file = new QFile;
file->setFileName(fileName);
file->open(QIODevice::Append | QIODevice::Text);
[..]
QTextStream out(file);
out.setCodec("UTF-8");
out << QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") << value << "\n";
I've been also trying using value.toUtf8().
After many unsuccessful tries, I have two possibilities to fix the encoding issue:
Plugin for Visual Studio: https://vlasovstudio.com/fix-file-encoding/, this plugin prevents Visual Studio from adding BOM to the beginning of the file, so that way all of my files can have UTF-8 encoding and raw strings can contain special character and they will be displayed/written without any issues,
This one is suggested by #MrEricSir in the comments. The idea is to use QStringLiteral function on string containing special characters.
Like this: QStringLiteral("ąśżęłóĄŚŻĘŁÓ");
I personally picked the first method since it don't force me to keep using additional functions everytime I'd like to print special characters. In both cases, results are the same.
Thanks for everyone who posted a comment and tried to help.

Beginner C++ Windows D2D1Circle Sample from MSDN Problem

So I was just going through the basic Windows Programming guide over at MSDN and attempted to do the D2D1Circle Sample in Module 3. The problem I encountered was an error my VC++ 2008 was throwing.
" 'CreateWindowExA' : cannot convert parameter 2 from 'PCWSTR' to 'LPCSTR'"
So, figuring that I had made a slight error while typing the code in I downloaded the sample code rar and opened it up and it threw the exact same error. Any ideas on how I can fix this so it will work. Also, does the fact that I'm programming on a x64 bit machine have anything to do with why it won't work? I know pointers carry different sized values dependent on the machine and both the parameters being called are pointers.
Update # Jollymorphic: In the first few modules, the MSDN tutorial was saying that there really isn't any reason to continue using ascii since unicode covers ascii and also supports all other languages like Chinese, Japanese, etc. Wouldn't implementing your solution cause my program to only support ascii and subsequently not allow support for east asian languages?
A PCWSTR is a pointer to wide (16-bit) characters. An LPCSTR is a pointer to regular (8-bit) characters. Your project probably is set to generate code based on the UNICODE character set. If you open the properties for your project in Visual Studio, and then navigate to the "General" page, you'll see a "Character Set" property. If it is currently set to "Use Unicode character set," then you can change it to "Use Multi-Byte character set," and your string literals will be generated as 8-bit character strings.