简体   繁体   中英

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

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.

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

they are C headers, you need C++ ones:

#include <cstdlib>
#include <cstdio>

EDIT:

First you have a bunch of errors from stdint.h ( C header!), then from cstrint . Just a guess, but if allegro is a C library (not C++ ), you also need to change

#include <allegro.h>

to

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

Apparently I can solve the problem by including allegro.h after sstream and fstream. I don't know why this fixes the problem (and I've seen other code including allegro.h first) but at least it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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