Eric Ahn
Eric Ahn

Reputation: 195

C++ errors - C4819, C2761, C2447

I am using Visual Studio 2017 to learn about SFML and sprite animations but I cannot get this code to run.

I have it saved with the encoding "Unicode (UTF-8 with signature) - Codepage 65001.

#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.loadFromFile("professor_walk_cycle_no_hat.png"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);

    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window: exit
            if (event.type == sf::Event::Closed)
                window.close();
        }
        // Clear screen
        window.clear();
        // Draw the sprite
        window.draw(sprite);
        // Update the window
        window.display();
    }
    return EXIT_SUCCESS;
}

I am getting the following errors/warnings:

Upvotes: 2

Views: 894

Answers (1)

Marc.2377
Marc.2377

Reputation: 8684

Your code has no invisible non-unicode characters that we can see, but when your system locale is set to Korean, you'll indeed get warning C4819.

In order to fix this, in addition to saving your source file as UTF-8, you must also specify the /utf-8 option to the Visual C++ compiler. Here's how:

  1. Open the project Property Pages dialog box.
  2. Expand the Configuration Properties, C/C++, Command Line folder.
  3. In Advanced Options, add the /utf-8 option, and specify your preferred encoding.
  4. Choose OK to save your changes.

(https://msdn.microsoft.com/en-us/library/mt708821.aspx)


With that out of the way... I could not reproduce errors C2761 and C2447. The code compiles and runs without issue. It is not a matter of C compilation (as opposed to C++) or else much more serious errors would arise. Let me know if it persists with /utf-8, so I can investigate some more.

Upvotes: 2

Related Questions