Vectorinhalt sortieren



  • Tagchen zusammen,
    in meinem Programm lese ich alle verfügbaren Schriftarten aus und speichere deren Namen in einen String-Vector. Da die Namen dort allerdings in beliebiger Reihenfolge stehen, wollte ich sie sortieren lassen:

    #include <algorithm>
    #include <vector>
    ...
    vector<std::string>vfonts;
    ...
    sort(vfonts.begin(),vfonts.end());
    

    Dieser Code funktioniert auch, allerdings irgendwie nur in Borland, wo ich das ganze getestet hatte. Da aber das Hauptprojekt in VS läuft, habe ich dort alles genauso gemacht, bekomme nun allerdings diese Fehler:

    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\vector(915) : see declaration of 'std::operator<'' c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\algorithm(1719): error C2784: 'bool std::operator <(const std::vector<\_Ty,\_Alloc> &,const std::vector<\_Ty,\_Alloc> &)' : could not deduce template argument for 'const std::vector<\_Ty,\_Ax> &' from 'std::allocator<\_Ty>::value\_type' with [ _Ty=std::string ] c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\vector(915) : see declaration of 'std::operator<''
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator<'' c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\algorithm(1719): error C2784: 'bool std::operator <(const std::reverse\_iterator<\_RanIt> &,const std::reverse\_iterator<\_RanIt> &)' : could not deduce template argument for 'const std::reverse\_iterator<\_RanIt> &' from 'std::allocator<\_Ty>::value\_type' with [ _Ty=std::string ] c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\xutility(655) : see declaration of 'std::operator<''
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator<'' c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\algorithm(1719): error C2784: 'bool std::operator <(const std::pair<\_Ty1,\_Ty2> &,const std::pair<\_Ty1,\_Ty2> &)' : could not deduce template argument for 'const std::pair<\_Ty1,\_Ty2> &' from 'std::allocator<\_Ty>::value\_type' with [ _Ty=std::string ] c:\\Programme\\Microsoft Visual Studio .NET 2003\\Vc7\\include\\utility(73) : see declaration of 'std::operator<''
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1719): error C2676: binary '<' : 'std::allocator<_Ty>::value_type' does not define this operator or a conversion to a type acceptable to the predefined operator
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Ax> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'std::allocator<_Ty>::value_type'
    with
    [
    _Ty=std::string
    ]
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1720): error C2676: binary '<' : 'std::allocator<_Ty>::value_type' does not define this operator or a conversion to a type acceptable to the predefined operator
    with
    [
    _Ty=std::string
    ]

    Anscheinend passt ihm etwas an der algorithm Datei nicht, nur ersetzen (mit der von Borland) kann ich sie nicht, da VS eine Borlandspezifische Dinge in der Datei nicht versteht. Weiß jemand was ich hierbei machen kann?

    greetz KN4CK3R



  • also bei mir im vs 2008 express funktioniert folgender code

    vector<std::string> names;
    names.push_back("a");
    names.push_back("b");
    names.push_back("c");
    sort(names.begin(),names.end());
    


  • ja, wie gesagt, funktionieren tut der Code einwandfrei. Nur in VS (Version 2003) bekomme ich die oben geposteten Fehler. Und außer sort habe ich keine vergleichbare Funktion gefunden, um Strings zu sortieren.

    greetz KN4CK3R



  • OT: Derselbe KN4CK3R wie in diversen CHEAT-Foren?



  • #include <string>
    


  • dust schrieb:

    OT: Derselbe KN4CK3R wie in diversen CHEAT-Foren?

    ja

    cheater schrieb:

    #include <string>
    

    ich schau in die Richtung mal weiter, obwohl der Header eigentlich schon dabei ist.

    greetz KN4CK3R


Anmelden zum Antworten