Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ VC++;2008 Express,看似正确的代码抛出错误_C++_Windows_File Io_Sdl_Stdio - Fatal编程技术网

C++ VC++;2008 Express,看似正确的代码抛出错误

C++ VC++;2008 Express,看似正确的代码抛出错误,c++,windows,file-io,sdl,stdio,C++,Windows,File Io,Sdl,Stdio,我已经试着重新开始编码一段时间了,所以我想我应该从一些简单的SDL开始,现在,没有文件I/o,这可以很好地编译,但是当我输入stdio代码时,它开始抛出错误。这一点我不确定,我看不出代码本身有任何问题,但是,就像我说的,我可能还是个新手,我想我来这里是想找一个对这类事情有更多经验的人来看看它 我猜我的问题归结为:“为什么微软不在微软Visual C++ 2008 Express下编译?” 我已经在代码段的底部附加了错误日志。提前感谢您的帮助 #include "SDL/SDL.h" #inclu

我已经试着重新开始编码一段时间了,所以我想我应该从一些简单的SDL开始,现在,没有文件I/o,这可以很好地编译,但是当我输入stdio代码时,它开始抛出错误。这一点我不确定,我看不出代码本身有任何问题,但是,就像我说的,我可能还是个新手,我想我来这里是想找一个对这类事情有更多经验的人来看看它

我猜我的问题归结为:“为什么微软不在微软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
尝试将名称stderr和stdout更改为其他名称。我怀疑编译器在抱怨,因为这些已经在C库的其他地方定义了

  • 您不需要声明、打开或关闭
    stdin
    stdout
    stderr
    ,这已在
    stdio
    中为您完成
  • 如果你使用C++,为什么不<代码> IOSWATION/CODE >?<李>
    @安东尼·克里夫:如果成功了,你能帮我一个忙,然后点击这篇文章旁边的复选标记图标吗?:)好了,我们得等它让我来。@Anthony聪明:谢谢:DUse
    freopen
    重定向
    stdout
    和friends。标准标题应该用尖括号括起来:
    。其次,C++中应该是:<代码> <代码>。最后,
    和朋友有什么问题?他们感到悲伤(@GMan:+1表示“他们感到悲伤。”比尔laughs@Gman:我不知道什么,我只是不知道更好的,我想。:(没关系。:)试试看,它们比C流安全、简单、灵活。
    #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;
    }