【问题标题】:Visual Studio: Unable to start program, the system cannot find the file specified visual studio error?Visual Studio:无法启动程序,系统找不到指定的文件 Visual Studio 错误?
【发布时间】:2021-08-08 14:23:49
【问题描述】:

我在这里使用的是 Visual Studio 2019 社区版。我从文件->新建->现有项目打开一个文件夹。但是每当我构建和运行我的程序时。它说

无法启动程序 'O:\1.Fourth 学期\programminh\main\Debug\Main2.exe' 系统找不到指定的文件

有很多节目。像bubble.cpp、binary.cpp,但它运行Main2.exe。

这是我的 linear.cpp 文件

#include <iostream>
using namespace std;
int main(){

            int n, an, arr[30], key, i, found=0;
            cout<<"Please enter number of element you want:"<<endl;

            cin>>n;
            cout<<"Please enter the numbers"<<endl;
            for(i=0;i<n;i++){
                cin>>arr[i];
            }


            cout<<"Please Enter the number you want to search"<<endl;
            cin>>key;

            for(i=0;i<n; i++){

                if(arr[i] == key){
                    cout<<"Element found at position "<<i+1;

                    found=1;
                    break;
                }
                }


                if(!found){
                    cout<<"Number Not Found"<<endl;
                }








            return 0;


}

有人可以看看吗?

【问题讨论】:

  • 代码似乎是可编译的。 (Test on coliru)。因此,我猜您的 VS 项目配置不正确。你没有透露任何关于这件事的事情。但是...... MS 在他们的网站上有一些(恕我直言非常好的)教程。也许,你应该先从那里开始。
  • 它是可编译的。我在代码块中运行它。没关系。但是我在视觉工作室中遇到了错误。即使我选择bubble.cpp,它也会运行我作为项目名称创建的main.exe
  • 即使我选择bubble.cpp,它也会运行我作为项目名称创建的main.exe 当然,它确实如此,因为它应该是这样工作的。仅供参考:MS: Solutions and projects in Visual Studio
  • @Scheff 它应该运行bubble.cpp吗?有很多cpp文件。它不应该运行我的目标文件吗?它打开了我第一次运行的程序。
  • 好的..我去看看..

标签: c++ visual-studio c++17 visual-studio-2019


【解决方案1】:

我从文件->新建->现有项目打开一个文件夹。

就我而言,您应该打开一个 .sln 文件而不是文件夹。

您只能运行 .sln 文件(Visual Studio 解决方案)而不是 .cpp 文件。

【讨论】:

  • 如何创建和打开 .sln 文件夹可视化。我在另一个文件夹中有很多 CPP 文件,我已经完成了代码块。它在代码块中运行良好,但每当我运行它时,Visual Studio 都会出现此错误。我想从我现有的文件夹中打开该文件夹并运行每个文件,如代码块。我该怎么做?
  • @Tusar Haque 就我而言,您无法在 Visual Studio 中运行 .cpp。 Visual Studio 不支持这一点。始终需要一个项目,即使它只包含一个源代码 (.cpp) 文件。您可以通过 Microsoft 的 C++ 编译器在命令行 (cl.exe) 上运行单个 .cpp 源文件,然后执行它。但这与 Visual Studio IDE 无关。
猜你喜欢
  • 2011-10-24
  • 1970-01-01
  • 2019-11-21
  • 2017-06-20
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多