| ÍøÕ¾Ê×Ò³ | Òµ½çÐÂÎÅ | С×é | Íþ¿Í | È˲Š| ÏÂÔØƵµÀ | ²©¿Í | ´úÂëÌù | ÔÚÏß±à³Ì | ±à³ÌÂÛ̳
»¶Ó­¼ÓÈëÎÒÃÇ£¬Ò»Í¬Çд輼Êõ
Óû§Ãû£º   
 
ÃÜ¡¡Â룺  
¹²ÓÐ 3161 È˹Ø×¢¹ý±¾Ìû
±êÌ⣺Ϊʲôͬһ¸ö³ÌÐòÔÚcmdºÍvs2012Àïµ÷ÊÔ½á¹û²»Í¬
È¡ÏûÖ»¿´Â¥Ö÷ ¼ÓÈëÊÕ²Ø
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
½áÌûÂÊ£º100%
ÊÕ²Ø
ÒѽáÌù¡Ì  ÎÊÌâµãÊý£º20 »Ø¸´´ÎÊý£º3 
Ϊʲôͬһ¸ö³ÌÐòÔÚ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;
}

ͼƬ¸½¼þ: ÓοÍûÓÐä¯ÀÀͼƬµÄȨÏÞ£¬Çë µÇ¼ »ò ×¢²á
ͼƬ¸½¼þ: ÓοÍûÓÐä¯ÀÀͼƬµÄȨÏÞ£¬Çë µÇ¼ »ò ×¢²á
ËÑË÷¸ü¶àÏà¹ØÖ÷ÌâµÄÌû×Ó: include¡¡limits¡¡
2016-08-24 19:29
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
»Ø¸´ 2Â¥ rjsp
û̫¶®£¬¿ÉÊÇÎÒ¶¨ÒåÁË´ò¿ªµÄ¾ø¶ÔĿ¼°¡£¬ÎÒÔÚÉè¶Ïµãºó¹Û²ì£¬Á½¸öĿ¼£¬Ò»¸ö¾ÍÄÜÕý³£´ò¿ª£¬
Ò»¸ö¾ÍÖ±½Ó´ò²»¿ª£¬¾Ö²¿±äÁ¿ÄÇЩҲһģһÑù£¬txtÀïµÄÎļþ¸ñʽҲһÑù¡£¶øÇÒcmdºÍvsÏÔʾµÄ²»Ò»Ñù£¬ºÃ¹îÒì°¡
2016-08-24 23:03
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
»Ø¸´ 4Â¥ rjsp
¿Ï¶¨ÊÇÎÒ¶¨ÒåµÄÄǸöĿ¼Ïµİ¡£¬Ôõô¸ÄÄØ£¬»¹ÓÐÎÒÏ벻ͨΪʲô»á³öÏÖ²»Í¬µÄÏÔʾ½á¹û
2016-08-25 00:15
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
ÓÖÒ»´Î¸Ðл°æÖ÷°¡£¬´óÉñ¹¦Á¦ÉîºñÄÄ
2016-08-25 19:18
¿ìËٻظ´£ºÎªÊ²Ã´Í¬Ò»¸ö³ÌÐòÔÚcmdºÍvs2012Àïµ÷ÊÔ½á¹û²»Í¬
Êý¾Ý¼ÓÔØÖÐ...
 
¡¡¡¡¡¡



¹ØÓÚÎÒÃÇ | ¹ã¸æºÏ×÷ | ±à³ÌÖйú | Çå³ýCookies | TOP | ÊÖ»ú°æ

±à³ÌÖйú °æȨËùÓУ¬²¢±£ÁôËùÓÐȨÀû¡£
Powered by Discuz, Processed in 0.017290 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved