无法在 Visual Studio 2013 上运行 C++ 程序
Can't run a C++ program on Visual Studio 2013
每当我尝试为我的课程作业运行程序时,我总是看到错误消息
"无法启动程序'C:\users\user\documents\visual studio 2013\projects\coursework\debug\ConsoleApplication1.exe'
系统找不到指定的文件
输出选项卡显示“
1>------ 构建开始:项目:ConsoleApplication1,配置:调试 Win32 ------
1> LINK : C:\Users\User\documents\visual studio 2013\Projects\Coursework\Debug\ConsoleApplication1.exe 未找到或未由上一个增量链接构建;执行完整链接
1> ConsoleApplication1.vcxproj -> C:\Users\User\documents\visual 工作室 2013\Projects\Coursework\Debug\ConsoleApplication1.exe
========== 构建:1 次成功,0 次失败,0 次更新,0 次跳过 ==========
“
程序编译成功但无法运行,怎么办?
编辑(应用代码):
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// Open the data file
ifstream inputFile;
inputFile.open("weir.txt");
if (inputFile.is_open())
{
int numberOfReadings;
float width;
float floodHeight;
// Read the values for number of readings, width and flood height
inputFile >> numberOfReadings;
inputFile >> width;
inputFile >> floodHeight;
// Use a loop to input the time, date and River height
for (int i = 0; i< numberOfReadings; i++) {
string time;
string date;
float riverHeight;
float flowrate;
// Read the data values to produce
inputFile >> time;
inputFile >> date;
inputFile >> riverHeight;
// Check if the river overflows
if (riverHeight > floodHeight) {
cout << "The river will flood" << endl;
}
else {
cout << "The river will not flood" << endl;
}
// Calculate the flow rate
flowrate = sqrt(9.81)*width*riverHeight*sqrt(riverHeight);
// Display all results
cout << "time : " << time << endl;
cout << "date : " << date << endl;
cout << "River height : " << riverHeight << endl;
cout << "Flow rate : " << flowrate << endl << endl << endl;
}
// Close the data file
inputFile.close();
// If data file does not open then produce an error message
}
else {
cout << "Error, the data file was not opened" << endl;
}
return 0;
}
您应该检查项目的属性,您可以在 配置属性 > C/C++ > 输出文件[= 下找到 "Output path" 之间可能存在差异14=] 和启动 .exe 的路径。您将在 配置属性 > 调试.
下找到正常启动 .exe 的路径
每当我尝试为我的课程作业运行程序时,我总是看到错误消息
"无法启动程序'C:\users\user\documents\visual studio 2013\projects\coursework\debug\ConsoleApplication1.exe'
系统找不到指定的文件
输出选项卡显示“
1>------ 构建开始:项目:ConsoleApplication1,配置:调试 Win32 ------
1> LINK : C:\Users\User\documents\visual studio 2013\Projects\Coursework\Debug\ConsoleApplication1.exe 未找到或未由上一个增量链接构建;执行完整链接
1> ConsoleApplication1.vcxproj -> C:\Users\User\documents\visual 工作室 2013\Projects\Coursework\Debug\ConsoleApplication1.exe
========== 构建:1 次成功,0 次失败,0 次更新,0 次跳过 ========== “
程序编译成功但无法运行,怎么办?
编辑(应用代码):
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// Open the data file
ifstream inputFile;
inputFile.open("weir.txt");
if (inputFile.is_open())
{
int numberOfReadings;
float width;
float floodHeight;
// Read the values for number of readings, width and flood height
inputFile >> numberOfReadings;
inputFile >> width;
inputFile >> floodHeight;
// Use a loop to input the time, date and River height
for (int i = 0; i< numberOfReadings; i++) {
string time;
string date;
float riverHeight;
float flowrate;
// Read the data values to produce
inputFile >> time;
inputFile >> date;
inputFile >> riverHeight;
// Check if the river overflows
if (riverHeight > floodHeight) {
cout << "The river will flood" << endl;
}
else {
cout << "The river will not flood" << endl;
}
// Calculate the flow rate
flowrate = sqrt(9.81)*width*riverHeight*sqrt(riverHeight);
// Display all results
cout << "time : " << time << endl;
cout << "date : " << date << endl;
cout << "River height : " << riverHeight << endl;
cout << "Flow rate : " << flowrate << endl << endl << endl;
}
// Close the data file
inputFile.close();
// If data file does not open then produce an error message
}
else {
cout << "Error, the data file was not opened" << endl;
}
return 0;
}
您应该检查项目的属性,您可以在 配置属性 > C/C++ > 输出文件[= 下找到 "Output path" 之间可能存在差异14=] 和启动 .exe 的路径。您将在 配置属性 > 调试.
下找到正常启动 .exe 的路径