简体   繁体   English

Visual Studio 14.0 使用 cstdint 和 stdint.h 给出编译错误

[英]Visual studio 14.0 giving compile errors with cstdint and stdint.h

I'm trying to build a c++ program using the allegro library for school, but I can't seem to get past a massive list of compile errors dealing with cstdint and stdint.h我正在尝试使用学校的 allegro 库构建一个 C++ 程序,但我似乎无法解决处理 cstdint 和 stdint.h 的大量编译错误

Removing all the code from my files gives me a header file with just this从我的文件中删除所有代码给了我一个头文件

#pragma once
#include <allegro.h>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <fstream>

and my main file just containing我的主文件只包含

#include "Trivia.h"

and here are the errors I'm trying to deal with这是我试图处理的错误

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4091: 'typedef ': ignored on left of 'signed char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): warning C4091: 'typedef ': ignored on left of 'short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): warning C4091: 'typedef ': ignored on left of 'int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): warning C4091: 'typedef ': ignored on left of '__int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4091: 'typedef ': ignored on left of 'unsigned char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4091: 'typedef ': ignored on left of 'unsigned short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4091: 'typedef ': ignored on left of 'unsigned int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4091: 'typedef ': ignored on left of 'unsigned __int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2059: syntax error: '::'

I can get the errors to disappear if I remove all of stdio.h, sstream and fstream but I kinda need those for my assignment.如果我删除所有 stdio.h、sstream 和 fstream,我可以让错误消失,但我的作业有点需要它们。

#include <stdlib.h>
#include <stdio.h>

they are C headers, you need C++ ones:它们是C头文件,您需要 C++ 头文件:

#include <cstdlib>
#include <cstdio>

EDIT:编辑:

First you have a bunch of errors from stdint.h ( C header!), then from cstrint .首先你有一堆来自stdint.hC头文件!)的错误,然后来自cstrint Just a guess, but if allegro is a C library (not C++ ), you also need to change只是猜测,但如果allegroC库(不是C++ ),您还需要更改

#include <allegro.h>

to

extern "C"
{
    #include <allegro.h>
}

Apparently I can solve the problem by including allegro.h after sstream and fstream.显然我可以通过在 sstream 和 fstream 之后包含 allegro.h 来解决这个问题。 I don't know why this fixes the problem (and I've seen other code including allegro.h first) but at least it works.我不知道为什么这解决了这个问题(我首先看到了包括 allegro.h 在内的其他代码)但至少它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM