[英]Can't run a C++ program on Visual Studio 2013
Whenever I try to run a program for my coursework I keep seeing the error message 每当我尝试为课程作业运行程序时,都会不断看到错误消息
"Unable to start program 'C:\\users\\user\\documents\\visual studio 2013\\projects\\coursework\\debug\\ConsoleApplication1.exe' “无法启动程序'C:\\ users \\ user \\ documents \\ Visual Studio 2013 \\ projects \\ coursework \\ debug \\ ConsoleApplication1.exe'
The system cannot find the file specified" 该系统找不到指定的文件”
The output tab shows " 输出标签显示“
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1> ------开始构建:项目:ConsoleApplication1,配置:调试Win32 ------
1> LINK : C:\\Users\\User\\documents\\visual studio 2013\\Projects\\Coursework\\Debug\\ConsoleApplication1.exe not found or not built by the last incremental link; 1>链接:上一个增量链接未找到或未构建C:\\ Users \\ User \\ documents \\ Visual Studio 2013 \\ Projects \\ Coursework \\ Debug \\ ConsoleApplication1.exe; performing full link
执行完整链接
1> ConsoleApplication1.vcxproj -> C:\\Users\\User\\documents\\visual studio 2013\\Projects\\Coursework\\Debug\\ConsoleApplication1.exe 1> ConsoleApplication1.vcxproj-> C:\\ Users \\ User \\ documents \\ visual studio 2013 \\ Projects \\课程\\ Debug \\ ConsoleApplication1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== " ==========构建:1成功,0失败,0最新,跳过0 ==========
The program builds successfully but will not run, what can I do? 该程序生成成功,但无法运行,该怎么办?
Edit (Application code): 编辑(应用代码):
#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;
}
You should check the properies of your project there is perhaps a difference between the "Output path" that you can find under Configuration properies > C/C++ > Output files and the path to start your .exe. 您应该检查项目的属性,在“ 配置属性”>“ C / C ++”>“输出文件 ”下可以找到的“输出路径”与启动.exe的路径之间可能存在差异。 You'll find the path to start the .exe normally under Configuration properies > Debugging .
您可以在“ 配置属性”>“调试”下找到正常启动.exe的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.