在使用Visual Studio 2017的C++中,我将一些头文件复制到了我的项目文件夹中,并在"c++解决方案资源管理器"下添加了它们。现在当我写代码时,
#include "name.h"
在包含(include)语句下,出现错误并显示"无法打开源文件"。
为什么会这样,有什么潜在的解决方法?
我刚刚下载了VS,第一次学习c++。
#include "name.h"
在包含(include)语句下,出现错误并显示"无法打开源文件"。
为什么会这样,有什么潜在的解决方法?
我刚刚下载了VS,第一次学习c++。
Visual Studio(或者更确切地说是编译器)需要知道在哪里查找包含的文件。请检查您在VS项目中的包含路径。
编辑:这个问题最近刚刚更新,这个答案已经不再相关。
对于那些仍然没有找到解决方法的人,请尝试修改/重新下载 Python,并勾选下载调试符号和下载调试二进制文件框。
在mslearn文章和这个有用的tutorial网站 DelftStack上阅读更多信息。
注意:如果您使用Microsoft Visual Studio IDE,则此答案很好。
通常情况下,当编译器无法找到头文件时,会出现此错误。
您可以尝试以下步骤:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int divide(int num, int den)
{
if(den==0)
{
return -1;
}
if((num%den)==0)
{
return 1;
}
else
{
return 0;
}
}
int divide(int a)
{
int j = a/2, flag = 1, i;
for(i=2; (i<=j) && (flag); i++)
{
if(a%i == 0)
{
flag = 0;
}
}
return flag;
}
void main()
{
clrscr();
int choice, res, a, b;
do
{
cout<<"1.Check for divisibility\n";
cout<<"2.Check for Prime\n";
cout<<"3.Exit\n";
cout<<"Enter your choice(1-3): ";
cin>>choice; cout<<"\n";
switch(choice)
{
case 1:
cout<<"Enter numerator and denominator: ";
cin>>a>>b;
res = divide(a, b);
if(res == -1)
{
cout<<"Divide by zero error..!!\n"; break;
}
cout<<((res) ? "It is" : "It is not")<<"\n";
break;
case 2:
cout<<"Enter the number: ";
cin>>a;
res = 0;
res = divide(a);
cout<<((res) ? "It is" : "It is not")<<"\n";
break;
case 3:
cout<<"Exiting...press any key...";
getch();
exit(1);
default:
cout<<"Wrong choice..!!";
}
cout<<"\n";
}while(choice>0 && choice<=3);
getch();
}