Reputation: 195
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:
Warning C4819 The file contains a character that cannot be represented in the current code page (949). Save the file in Unicode format to prevent data loss HelloSFML line: 1
Severity Code Description Project File Line Suppression State Error C2761 '{ctor}': redeclaration of member is not allowed line: 3
Severity Code Description Project File Line Suppression State Error C2447 '{': missing function header (old-style formal list?) line: 4
Upvotes: 2
Views: 894
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:
- Open the project Property Pages dialog box.
- Expand the Configuration Properties, C/C++, Command Line folder.
- In Advanced Options, add the /utf-8 option, and specify your preferred encoding.
- Choose OK to save your changes.
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