C++ C++;错误-C4819、C2761、C2447
我正在使用Visual Studio 2017学习SFML和sprite动画,但我无法运行此代码 我用编码“Unicode(带签名的UTF-8)-代码页65001”保存它C++ C++;错误-C4819、C2761、C2447,c++,C++,我正在使用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
#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;
}
#包括
#包括
int main()
{
//创建主窗口
sf::RenderWindow窗口(sf::VideoMode(800600),“SFML窗口”);
//加载要显示的精灵
sf::纹理;
如果(!texture.loadFromFile(“professor\u walk\u cycle\u no\u hat.png”))
返回退出失败;
雪碧雪碧(纹理);
//开始游戏循环
while(window.isOpen())
{
//处理事件
sf::事件;
while(window.pollEvent(事件))
{
//关闭窗口:退出
如果(event.type==sf::event::Closed)
window.close();
}
//清屏
window.clear();
//画精灵
窗口。绘制(精灵);
//更新窗口
window.display();
}
返回退出成功;
}
我收到以下错误/警告:
- 警告C4819文件包含无法在当前代码页(949)中表示的字符。请以Unicode格式保存文件以防止数据丢失HelloSFML行:1
- 严重性代码说明项目文件行抑制状态 错误C2761“{ctor}”:不允许在第3行重新声明成员
- 严重性代码说明项目文件行抑制状态 错误C2447“{”:缺少函数头(旧式正式列表?)行:4
为了摆脱这个问题,除了将源文件保存为UTF-8(您已经做到了)之外,还必须在VisualC++编译器中指定<强> >代码> /UTF-8< /代码> <强>选项。
有了这些,我就无法重现错误C2761和C2447。代码编译和运行都没有问题。这不是C编译(与C++相反)的问题,否则会出现更严重的错误。请告诉我它是否会持续出现
/utf-8
,这样我就可以进行更多的研究。int main()
应为int main(int argc,char**argv)<代码>你确信你是把它编译成C++而不是C吗?最后一个错误看起来好像它是C程序。@ BARMAR是的,它不一定是C++。Barmar。这个例子是完全合法的。@ EriaCn你使用的是什么版本的Windows?哪个语言?真的很晚才回答,我已经厌倦了这个错误,我重新安装了VS 2017,现在它工作了,我甚至不知道为什么…@EricAhn很有趣。谢谢你让我知道。问候。