1
我正在使用Visual Studio 2012 Premium。当此代码正常执行(不在调试器中)时,唯一的输出是空行。但是当它在调试器中运行时,输出是“1月9日8”。在Debug和Release之间切换并没有什么区别,并且使用#pragma optimize(“”,off)关闭main()函数的优化什么也不做。我能做些什么来输出“1月9日8”?在非调试模式下运行代码的问题
P02.cpp包含:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
system("cls");
string s = "";
ifstream tt;
tt.open("P02.DAT");
getline(tt, s);
cout << s << endl;
return 0;
}
P02.DAT包含:
January 9 8
February 19 17
March 20 23
April 20 15
May 15 16
June 8 7
July 12 9
August 20 18
September 21 27
October 18 17
November 19 24
December 18 17
请检查文件是否已成功打开。 –
使用绝对路径 - 检查是否有帮助 – marcinj
添加到您的程序**命令(“cmd/c dir”)** - 输出应该包括P02.DAT –