The problem with sorting a char[10][100] is that the element that you are sorting (a char[100]) is not an l-value, and std::sort() requires that what you're sorting is an l-value. A wrapper for the array is required:
Originally posted by Andreas Masur
Well...one side note....you should not use 'qsort()' with STL types like 'vector' for several reasons like for example:
'qsort()' is not guaranteed to work with non-POD types (structures and classes)
'qsort()' is not type-safe
Not only that, the compiler can optimize std::sort and the functor more aggressively than qsort(). In truth, there is no reason whatsoever to use qsort() in a C++ program unless the compiler's library doesn't have STL (which is rare).
Even if the compiler doesn't have STL, you still end up having to write your own sort, since as you pointed out, qsort() is not guaranteed to work for non-POD types.
this is equivilant to S[3][??] ??
how many characters does it takes in?
sorry quite new to STL stuff
Paul: i get 4 warning with your code.....
warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
And 1 more serious problem... fstream f.open cannot open the array....
error C2664: 'fopen' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
wad is that? anyways to solve?
Thanks
Last edited by ayumi; August 28th, 2003 at 06:34 AM.
this is equivilant to S[3][??] ??
how many characters does it takes in?
A vector is a dynamic array. The vector type is std::string. The vector has 3 std::strings, each initialized to "". A std::string grows dynamically, so the number of characters that can be stored is theoretically unlimited.
Paul: i get 4 warning with your code.....
Those warnings only mean that the debugger will recognize only the first 255 characters. They are harmless and can be turned off with
#pragma warning (disable : 4786)
And 1 more serious problem... fstream f.open cannot open the array....
error C2664: 'fopen' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
Originally posted by ayumi
warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >
>::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
Bookmarks