| ÍøÕ¾Ê×Ò³ | Òµ½çÐÂÎÅ | С×é | Íþ¿Í | È˲Š| ÏÂÔØƵµÀ | ²©¿Í | ´úÂëÌù | ÔÚÏß±à³Ì | ±à³ÌÂÛ̳
»¶Ó­¼ÓÈëÎÒÃÇ£¬Ò»Í¬Çд輼Êõ
Óû§Ãû£º   
 
ÃÜ¡¡Â룺  
¹²ÓÐ 3188 È˹Ø×¢¹ý±¾Ìû
±êÌ⣺Ϊʲôͬһ¸ö³ÌÐòÔÚcmdºÍvs2012Àïµ÷ÊÔ½á¹û²»Í¬
Ö»¿´Â¥Ö÷ ¼ÓÈëÊÕ²Ø
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
½áÌûÂÊ£º100%
ÊÕ²Ø
ÒѽáÌù¡Ì  ÎÊÌâµãÊý£º20 »Ø¸´´ÎÊý£º6 
Ϊʲôͬһ¸ö³ÌÐòÔÚ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
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
µÈ¡¡¼¶£º°æÖ÷
Íþ¡¡Íû£º528
Ìû¡¡×Ó£º9024
ר¼Ò·Ö£º54030
×¢¡¡²á£º2011-1-18
ÊÕ²Ø
µÃ·Ö:0 
ÊÖ»úÉÏû·¨×Ðϸ¿´£¬¾¹È»É¾µôÁËÉèÖÃlocaleÄǾ䡣»ØÕýÌ⣺ÒòΪ´ò¿ªÎļþʱ²ÎÊýÖ»°üº¬ÎļþÃû£¬ÄÇôËü¾ÍÊÇ´ò¿ª¡°µ±Ç°Ä¿Â¼¡±£¨¿ÉÓÃwinapiº¯ÊýGetCurrentDirectory»îµÃµ±Ç°Ä¿Â¼£©ÏµÄÎļþ¡£
2016-08-24 21:35
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
»Ø¸´ 2Â¥ rjsp
û̫¶®£¬¿ÉÊÇÎÒ¶¨ÒåÁË´ò¿ªµÄ¾ø¶ÔĿ¼°¡£¬ÎÒÔÚÉè¶Ïµãºó¹Û²ì£¬Á½¸öĿ¼£¬Ò»¸ö¾ÍÄÜÕý³£´ò¿ª£¬
Ò»¸ö¾ÍÖ±½Ó´ò²»¿ª£¬¾Ö²¿±äÁ¿ÄÇЩҲһģһÑù£¬txtÀïµÄÎļþ¸ñʽҲһÑù¡£¶øÇÒcmdºÍvsÏÔʾµÄ²»Ò»Ñù£¬ºÃ¹îÒì°¡
2016-08-24 23:03
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
µÈ¡¡¼¶£º°æÖ÷
Íþ¡¡Íû£º528
Ìû¡¡×Ó£º9024
ר¼Ò·Ö£º54030
×¢¡¡²á£º2011-1-18
ÊÕ²Ø
µÃ·Ö:0 
µ±Ä㽫¡±1.txt"´«¸øfooº¯Êýºó£¬ÄãÈÏΪfooº¯ÊýÓ¦¸Ã´ò¿ªÄĸöĿ¼ÏµÄ1.txt¡£ÊÇCÅÌAĿ¼ÏµÄ1.txt»¹ÊÇDÅÌabcĿ¼ÏµÄ1.txt£¬ÒÖ»òÊÇÆäËü£¿
2016-08-24 23:37
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
»Ø¸´ 4Â¥ rjsp
¿Ï¶¨ÊÇÎÒ¶¨ÒåµÄÄǸöĿ¼Ïµİ¡£¬Ôõô¸ÄÄØ£¬»¹ÓÐÎÒÏ벻ͨΪʲô»á³öÏÖ²»Í¬µÄÏÔʾ½á¹û
2016-08-25 00:15
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
µÈ¡¡¼¶£º°æÖ÷
Íþ¡¡Íû£º528
Ìû¡¡×Ó£º9024
ר¼Ò·Ö£º54030
×¢¡¡²á£º2011-1-18
ÊÕ²Ø
µÃ·Ö:20 
ÒÔÏÂÊÇÒýÓÃrjspÔÚ2016-8-24 23:37:36µÄ·¢ÑÔ£º

µ±Ä㽫¡±1.txt"´«¸øfooº¯Êýºó£¬ÄãÈÏΪfooº¯ÊýÓ¦¸Ã´ò¿ªÄĸöĿ¼ÏµÄ1.txt¡£ÊÇCÅÌAĿ¼ÏµÄ1.txt»¹ÊÇDÅÌabcĿ¼ÏµÄ1.txt£¬ÒÖ»òÊÇÆäËü£¿
ƾʲôfooÄÜÖªµÀ"1.txt"¾ÍÊÇ"D:\\VS2012\\CPP\\linemax1\\linemax1\\1.txt"£¿
¼ÙÈçÄãÔÚmainº¯ÊýÖв»ÊÇËÑË÷Ò»¸öĿ¼£¬¶øÊÇËÑË÷Á½¸öĿ¼£¬±ÈÈçËÑË÷C:\ºÍD:\£¬Äã´«¸øfooÒ»¸ö"1.txt"£¬fooÊÇÉñÏÉÄÜ·Ö±æ³öÄãÏë´ò¿ªC:\1.txt»¹ÊÇD:\1.txt£¿
¾ÍÊÇÔÚÏÖʵÉú»îÖУ¬Èç¹ûÄãµÄÀÏ°åÒªÇó¡°½«¿Õµ÷ÇåÀíһϡ±£¬Äã¿Ï¶¨Ò²µÃÎÊÒ»¾ä¡°ÊÇÄĸö·¿¼äµÄ¿Õµ÷£¿¡±£¬ÎªÊ²Ã´µ½Á˳ÌÐòÉè¼Æʱ¾ÍÈÏΪfooÄÜÉñÏÉ°ãÖªµÀÊÇÄĸöĿ¼ÏµÄ"1.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( void )
{
    const char* searchfolder = "D:\\VS2012\\CPP\\linemax1\\linemax1\\";
    const char* searchfilter = "*.txt";


    std::locale loc = std::locale::global( std::locale(std::locale(),"",std::locale::ctype) );

    int maxval_of_allfile;
    vector<string> allfile_with_maxval;

    bool bfound = false;
    _finddata_t sFind;
    intptr_t lResult = _findfirst( (string(searchfolder)+searchfilter).c_str(), &sFind );
    if( lResult != -1 )
    {
        do
        {
            if( (sFind.attrib&_A_SUBDIR) == 0 )
            {
                bfound = true;

                cout << sFind.name << ":\n";
                int maxval;
                switch( foo((string(searchfolder)+sFind.name).c_str(),maxval) )
                {
                case 0:
                    cout << "\t[OUTPUT] ×î´óÖµ = " << maxval << '\n';
                    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;
                }
            }
        }
        while( _findnext(lResult,&sFind) != -1 );

        _findclose( lResult );
    }
    if( errno != ENOENT )
    {
        cout << strerror(errno) << '\n';
        return 1;
    }
    else if( !bfound )
    {
        cout << "ûÓÐÕÒµ½Æ¥ÅäµÄÎļþ.\n";
        return 2;
    }

    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';
    }

    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;
}
2016-08-25 08:31
Çà×ÏÄ«
Rank: 2
µÈ¡¡¼¶£ºÂÛ̳ÓÎÃñ
Ìû¡¡×Ó£º67
ר¼Ò·Ö£º20
×¢¡¡²á£º2016-8-10
ÊÕ²Ø
µÃ·Ö:0 
ÓÖÒ»´Î¸Ðл°æÖ÷°¡£¬´óÉñ¹¦Á¦ÉîºñÄÄ
2016-08-25 19:18
¿ìËٻظ´£ºÎªÊ²Ã´Í¬Ò»¸ö³ÌÐòÔÚcmdºÍvs2012Àïµ÷ÊÔ½á¹û²»Í¬
Êý¾Ý¼ÓÔØÖÐ...
 
¡¡¡¡¡¡



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

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