gpt4 book ai didi

C++ 错误 - C4819、C2761、C2447

转载 作者:搜寻专家 更新时间:2023-10-31 02:06:53 25 4
gpt4 key购买 nike

我正在使用 Visual Studio 2017 来了解 SFML 和 Sprite 动画,但我无法运行此代码。

我用编码“Unicode(带签名的 UTF-8)- 代码页 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;
}

我收到以下错误/警告:

  • 警告 C4819 文件包含当前代码页 (949) 无法表示的字符。以 Unicode 格式保存文件,防止数据丢失 HelloSFML line: 1

  • 严重性代码描述项目文件行抑制状态错误 C2761“{ctor}”:不允许重新声明成员行:3

  • 严重性代码描述项目文件行抑制状态错误 C2447“{”:缺少函数头(旧式正式列表?)行:4

最佳答案

您的代码没有我们可以看到的不可见的非 unicode 字符,但是当您的系统区域设置为韩语时,您确实会得到 warning C4819 .

要摆脱这种情况,除了将源文件保存为 UTF-8(您这样做)之外,您还必须指定 /utf-8 选项到 Visual C++ 编译器。方法如下:

  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)


除此之外...我无法重现错误 C2761 和 C2447。代码编译并运行没有问题。这不是 C 编译(与 C++ 相对)的问题,否则会出现更严重的错误。如果 /utf-8 仍然存在,请告诉我,以便我进行更多调查。

关于C++ 错误 - C4819、C2761、C2447,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49567108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com