我在Windows上的Visual Studio中编写了一个程序,程序编译正确,但没有将所需的输出显示到控制台。但是,如果我在Linux上的Gedit中编译和运行该程序,则会显示正确的输出并且一切正常。为什么是这样?代码如下:C++代码在Gedit中工作,但不在VS中
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string input;
cout << "College Admission Generator\n\n";
cout << "To begin, enter the location of the input file (e.g. C:\\yourfile.txt):\n";
cin >> input;
ifstream in(input.c_str());
if (!in)
{
cout << "Specified file not found. Exiting... \n\n";
return 1;
}
char school, alumni;
double GPA, mathSAT, verbalSAT;
int liberalArtsSchoolSeats = 5, musicSchoolSeats = 3, i = 0;
while (in >> school >> GPA >> mathSAT >> verbalSAT >> alumni)
{
i++;
cout << "Applicant #: " << i << endl;
cout << "School = " << school;
cout << "\tGPA = " << GPA;
cout << "\tMath = " << mathSAT;
cout << "\tVerbal = " << verbalSAT;
cout << "\tAlumnus = " << alumni << endl;
if (school == 'L')
{
cout << "Applying to Liberal Arts\n";
if (liberalArtsSchoolSeats > 0)
{
if (alumni == 'Y')
{
if (GPA < 3.0)
{
cout << "Rejected - High school Grade is too low\n\n";
}
else if (mathSAT + verbalSAT < 1000)
{
cout << "Rejected - SAT is too low\n\n";
}
else
{
cout << "Accepted to Liberal Arts!!\n\n";
liberalArtsSchoolSeats--;
}
}
else
{
if (GPA < 3.5)
{
cout << "Rejected - High school Grade is too low\n\n";
}
else if (mathSAT + verbalSAT < 1200)
{
cout << "Rejected - SAT is too low\n\n";
}
else
{
cout << "Accepted to Liberal Arts\n\n";
liberalArtsSchoolSeats--;
}
}
}
else
{
cout << "Rejected - All the seats are full \n";
}
}
else
{
cout << "Applying to Music\n";
if (musicSchoolSeats>0)
{
if (mathSAT + verbalSAT < 500)
{
cout << "Rejected - SAT is too low\n\n";
}
else
{
cout << "Accepted to Music\n\n";
musicSchoolSeats--;
}
}
else
{
cout << "Rejected - All the seats are full\n";
}
}
cout << "*******************************\n";
}
return 0;
}
感谢您的任何和所有帮助!
编辑:删除绒毛。
为了澄清,该程序在VS编译。它打开文件,但不会回显文件中的任何信息,而只是打印“按任意键退出...”。信息。
你看到了什么错误信息?它编译了吗?也许你只需要包括'#include'? –
wally
它在哪里不起作用,它究竟如何不起作用,与编辑器无关,可能是错误的文件,也可能是编译器等 –