#beginner's problem
16 messages · Page 1 of 1 (latest)
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.
You can't use char *.
https://stackoverflow.com/a/50407375
so Is my code wrong?but Why did I have to click "GBK" in the lower right corner and then make the conversion in order to get the output to be normal?
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:
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;
ok,thanks
You absolutely can
Maybe, but it would be atrocious to use.
Definetly not something I'd recommend to a beginner
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";
}
Does this work for you? Ensure that the source file is saved in the UTF-8 encoding. If your compiler is MSVC, additionally pass the /utf-8 flag
I mean, it has nothing to do with unicode support. It's not a good idea in general, yeah
@sturdy elbow Has your question been resolved? If so, type !solved :)