为什么同一个程序在cmd和vs2012里调试结果不同
下面是同一个程序的在cmd和vs2012里的不同显示结果,还有为什么不同路径下有的txt可以打开有的打开失败呢?求指教啊代码:
#include <io.h>
#include <cstring>
#include <cerrno>
#include <iostream>
#include <fstream>
#include <sstream>
#include <locale>
#include <string>
#include <limits>
#include <vector>
#include <algorithm>
using namespace std;
// 0: 成功
// -1: 文件打开失败
// -2: 未找到int类型数值
int foo( const char* filename, int& maxval );
int main()
{
string fileName = "D:\\VS2012\\CPP\\linemax1\\linemax1\\*.txt";
int maxval_of_allfile;
vector<string> allfile_with_maxval;
_finddata_t sFind;
long handle = _findfirst(fileName.c_str(), &sFind);
bool bfound = false;
if (handle == -1L)
{
cerr << "failed to transfer files" << endl;
return false;
}
do
{
if( (sFind.attrib&_A_SUBDIR) == 0 )
{
bfound = true;
cout << sFind.name << ":\n";
int maxval;
switch( foo(sFind.name,maxval) )
{
case 0:
cout << "\t[OUTPUT] 最大值 = " << maxval << '\n';
if(maxval>10||maxval<-10)
{
cout<<"Beyond"<<endl;
cout<<'\a'<<endl;
}
if( allfile_with_maxval.empty() )
{
maxval_of_allfile = maxval;
allfile_with_maxval.push_back( sFind.name );
}
else if( maxval == maxval_of_allfile )
{
allfile_with_maxval.push_back( sFind.name );
}
else if( maxval > maxval_of_allfile )
{
maxval_of_allfile = maxval;
allfile_with_maxval.clear();
allfile_with_maxval.push_back( sFind.name );
}
break;
case -1:
cout << "\t[ERROR] 文件打开失败.\n";
break;
case -2:
cout << "\t[WARNING] 未找到int类型数值.\n";
break;
}//cout <<sFind.name <<endl;
}
} while (_findnext(handle, &sFind) == 0);
//system("pause");
//return true;
if( allfile_with_maxval.empty() )
cout << "所有匹配的文件中皆无int类型.\n";
else
{
cout << "在所有匹配的文件中,拥有最大值(" << maxval_of_allfile << ")的文件是:\n";
for( size_t i=0; i!=allfile_with_maxval.size(); ++i )
cout << '\t' << allfile_with_maxval[i] << '\n';
}
system("pause");
return 0;
}
int foo( const char* filename, int& maxval )
{
maxval = std::numeric_limits<int>::min();
ifstream is( filename );
if( !is )
return -1;
bool bfound = false;
for( string s; is>>s; )
{
istringstream ss( s );
int val;
if( ss>>val && ss.eof() )
{
bfound = true;
maxval = max( maxval, val );
}
}
if( !bfound )
return -2;
return 0;
}
