[英]Compiler issues on VC++ 2008 Express, Seemingly correct code throws errors
我一直在嘗試重新編碼,因此我以為我會從一些簡單的SDL開始,現在,沒有文件I / O,這可以很好地編譯,但是當我輸入stdio代碼時,它就開始了引發錯誤。 我不確定這一點,我認為代碼本身沒有任何問題,但是,就像我說的那樣,我最好還是一個新手,並認為我會來這里找一些有更多經驗的人這種東西要看一下。
我想我的問題可以歸結為:“為什么不使用Microsoft的Visual C ++ 2008 Express進行編譯?”
我在代碼段的底部附加了錯誤日志。 在此先感謝您的幫助。
#include "SDL/SDL.h"
#include "stdio.h"
int main(int argc, char *argv[])
{
FILE *stderr;
FILE *stdout;
stderr = fopen("stderr", "wb");
stdout = fopen("stdout", "wb");
SDL_Init(SDL_INIT_EVERYTHING);
fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
SDL_Quit();
fprintf(stderr, "SDL QUIT.\n");
fclose(stderr);
fclose(stdout);
return 0;
}
報告的實際錯誤:
main.cpp(6) : error C2090: function returns array
main.cpp(6) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(6) : error C2556: 'FILE ***__iob_func(void)' : overloaded function differs only by return type from 'FILE *__iob_func(void)'
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(132) : see declaration of '__iob_func'
main.cpp(7) : error C2090: function returns array
main.cpp(7) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(9) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(10) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(13) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(15) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(17) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(18) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
#include "SDL/SDL.h"
#include "stdio.h"
int main(int argc, char *argv[])
{
FILE *stderr; //Invalid names. These are already defined by stdio.h.
FILE *stdout; //You can't use them (portably anyway).
stderr = fopen("stderr", "wb"); //I'm assuming you actually want files
stdout = fopen("stdout", "wb"); //called "stderror" and "stdout".
SDL_Init(SDL_INIT_EVERYTHING);
fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
SDL_Quit();
fprintf(stderr, "SDL QUIT.\n");
fclose(stderr);
fclose(stdout);
return 0;
}
嘗試將名稱stderr和stdout更改為其他名稱。 我懷疑編譯器在抱怨,因為這些已經在C庫的其他地方定義了。
stdin
, stdout
或stderr
,這已經在stdio
為您完成了。 iostream
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.