Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.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++ 开发c++;代码未在Vic+中运行+;(代码块vs Visual Studio)_C++_Visual Studio_Codeblocks - Fatal编程技术网

C++ 开发c++;代码未在Vic+中运行+;(代码块vs Visual Studio)

C++ 开发c++;代码未在Vic+中运行+;(代码块vs Visual Studio),c++,visual-studio,codeblocks,C++,Visual Studio,Codeblocks,由于一些奇怪的原因,文件声明在VisualStudio中的工作方式与在代码块中的不同。 下面的代码在代码中运行得非常好:块,但不会在VisualStudio中运行,我不知道为什么不能找到它 int n; FILE * pFile; pFile = fopen ("date.in","r"); fscanf(pFile,"%d",&n); printf("%d", n); return 0; 分别使用cstdio和stdafx 编辑1: 触发stdio.h的断点行1061问题是您没有检查

由于一些奇怪的原因,文件声明在VisualStudio中的工作方式与在代码块中的不同。 下面的代码在代码中运行得非常好:块,但不会在VisualStudio中运行,我不知道为什么不能找到它

int n;
FILE * pFile;
pFile = fopen ("date.in","r");
fscanf(pFile,"%d",&n);
printf("%d", n);
return 0;
分别使用cstdio和stdafx 编辑1:


触发stdio.h的断点行1061

问题是您没有检查
fopen
的结果,因此失败。这几乎可以肯定,因为程序运行时,
data.in
不在当前目录中(而是其他目录)


可以在项目属性中指定运行程序时的当前目录。或者,在命令行上传递数据文件的完整路径,并在项目属性中指定程序的参数。

该代码不会按原样编译。我们需要一个请。请比“不会编译”更具体。复制和粘贴错误。我已经恢复了C++标签。C中没有CSTDIO头,但C++中有。(您可能会争辩说,这段代码完全可以用C编写,我也同意,但事实并非如此。)我认为问题在于没有找到文件,但您仍然试图从中读取。这与编译无关。请记住,在Visual Studio中调试/运行时,默认文件夹是包含项目文件而不是可执行文件的文件夹。除非您在VisualStudio中修改了默认设置。
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int d;
int main ()
{
FILE * inFile;
inFile = fopen("date.in", "r");
fscanf(inFile, "%d", &d);
printf("%d", d);
return 0;
}