OneLoneCoder / CommandLineFPS

A First Person Shooter at the command line? Yup...
599 stars 173 forks source link

Noobie errors! #4

Open sukhchainn opened 5 years ago

sukhchainn commented 5 years ago

When I compiled the program this happened, please tell me what to do.

$ g++ -std=gnu++17 -o game CommandLineFPS.cpp CommandLineFPS.cpp: In function 'int main()': CommandLineFPS.cpp:267:114: error: 'swprintf_s' was not declared in this scope swprintf_s(screen, 40, L"X=%3.2f, Y=%3.2f, A=%3.2f FPS=%3.2f ", fPlayerX, fPlayerY, fPlayerA, 1.0f/fElapsedTime); ^ CommandLineFPS.cpp:279:103: error: cannot convert 'wchar_t' to 'LPCSTR {aka const char}' for argument '2' to 'BOOL WriteConsoleOutputCharacterA(HANDLE, LPCSTR, DWORD, COORD, PDWORD)' WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0,0 }, &dwBytesWritten); ^

NotSoSmartGames commented 5 years ago

I'm not sure what you need to do in *nix but for Visual Studio you need to change the compiler over to UNICODE. To do this you goto Project -> Properties -> General -> Character Set -> Use Unicode Character Set.

Here is a link that talks about changing the character set for g++: https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html

ghost commented 5 years ago

I tried to compile this in CodeBlocks and it does not work. What do I do?

minh25 commented 5 years ago

I don't know how to compile this in cmd. Please tell me what to do.

Altareon98 commented 4 years ago

@Quake504 In case that you still need to solve this...

I tried the option posted here https://stackoverflow.com/questions/61880906/c-errorinvalid-conversion-from-int-to-const-wchar-t-because-of-swprintf

Just add a W to the method: WriteConsoleOutputCharacter(...) -> WriteConsoleOutputCharacterW(...) and it must work when you try to compile it on Code Blocks. It worked for me ;)