#beginner's problem

16 messages · Page 1 of 1 (latest)

sturdy elbow
#

I have set the encoding of UTF-8,but why is the string part of my code still outputtong garbled characters?

earnest sparrowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

round badge
sturdy elbow
round badge
# sturdy elbow so Is my code wrong?but Why did I have to click "GBK" in the lower right corner ...

I have no idea what GBK is.
In general I don't really know how to print unicode.
Just do yourself a favour, especially if you're a beginner, and keep everything in English. Code, comments, etc, everything in English.

Not only will you not have any encoding problems, but you'll also be able to share your code on this server and receive help, whereas if the code were in Taiwanese or whatever language that is, then you can't get help from international servers such as this.

#

Also:

earnest sparrowBOT
#
Why Is `using namespace std` Considered Bad Practice?

using namespace std will import all the symbols from std into the enclosing namespace. This can easily lead to name collisions, as the standard library is filled with common names: get, count, map, array, etc.

A key concern with using namespace std; is not what is imported now but rather what may suddenly be imported in the future.

While using namespace std; is alright for tiny projects, it is important to move away from it as soon as possible. Consider less intrusive alternatives:

// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x;
thorny mantle
round badge
thorny mantle
#

Try this:

#include <iostream>

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX 1
#include <windows.h>
#endif

int main()
{
    #ifdef _WIN32
    SetConsoleCP(CP_UTF8);
    SetConsoleOutputCP(CP_UTF8);
    #endif

    std::cout << "Привет!\n";
}
thorny mantle
thorny mantle
earnest sparrowBOT
#

@sturdy elbow Has your question been resolved? If so, type !solved :)