g*****1 发帖数: 998 | 1 下面这段代码,在vc express2010里编译通不过,但是我试了g++就可以。
另外,我把string vector改成注解掉的那段里的int vector, vc就可以通过。
请问我这个应该怎么改一下呢?我希望在vc里用。
#include
#include
#include
#include
using namespace std;
int main () {
char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1);
vector u;
/* int m1[] = {1,2,3,4};
vector v1(m1,m1+4);
int m2[] ={100};
vector v2(m2,m2+1);
vector u;*/
set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(u));
return 0;
} | g*********s 发帖数: 1782 | 2 looks fine to me. have u tried "char*" to "const char*" in vc?
what errors vc reports? also try g++ -Wall to see what warnings g++ has.
【在 g*****1 的大作中提到】 : 下面这段代码,在vc express2010里编译通不过,但是我试了g++就可以。 : 另外,我把string vector改成注解掉的那段里的int vector, vc就可以通过。 : 请问我这个应该怎么改一下呢?我希望在vc里用。 : #include : #include : #include : #include : using namespace std; : int main () { :
| g*****1 发帖数: 998 | 3 g++里warning:deprecated conversion from string constant to 'char*'
刚试了"char*" to "const char*" in vc 还是不行。。
vc里的compile error很多,以下是第一个:
g:\program files\microsoft visual studio 10.0\vc\include\algorithm(4296):
error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const
std::move_iterator<_RanIt2> &)' : could not deduce template argument for '
const std::move_iterator<_RanIt> &' from 'std::basic_string<_Elem,_Traits,_
Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits,
1> _Ax=std::allocator
1> ]
【在 g*********s 的大作中提到】 : looks fine to me. have u tried "char*" to "const char*" in vc? : what errors vc reports? also try g++ -Wall to see what warnings g++ has.
| S**I 发帖数: 15689 | 4 error message说的很清楚:string类的operator<没有定义,改成这样子就行了:
#include
#include
#include
#include
#include
using namespace std;
bool comp(const string& s1, const string& s2){
return strcmp(s1.c_str(), s2.c_str()) < 0;
}
int main () {
char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1);
vector u;
/* int m1[] = {1,2,3,4};
vector v1(m1,m1+4);
int m2[] ={100};
vector v2(m2,m2+1);
vector u;*/
set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(u), (
bool(*)(const string&, const string&)) comp);
return 0;
}
const
【在 g*****1 的大作中提到】 : g++里warning:deprecated conversion from string constant to 'char*' : 刚试了"char*" to "const char*" in vc 还是不行。。 : vc里的compile error很多,以下是第一个: : g:\program files\microsoft visual studio 10.0\vc\include\algorithm(4296): : error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const : std::move_iterator<_RanIt2> &)' : could not deduce template argument for ' : const std::move_iterator<_RanIt> &' from 'std::basic_string<_Elem,_Traits,_ : Ax>' : 1> with : 1> [
| g*****1 发帖数: 998 | 5 谢谢!
【在 S**I 的大作中提到】 : error message说的很清楚:string类的operator<没有定义,改成这样子就行了: : #include : #include : #include : #include : #include : using namespace std; : bool comp(const string& s1, const string& s2){ : return strcmp(s1.c_str(), s2.c_str()) < 0; : }
| c******e 发帖数: 1032 | | p*****a 发帖数: 147 | 7 这个我试了下,好像还是不work
【在 S**I 的大作中提到】 : error message说的很清楚:string类的operator<没有定义,改成这样子就行了: : #include : #include : #include : #include : #include : using namespace std; : bool comp(const string& s1, const string& s2){ : return strcmp(s1.c_str(), s2.c_str()) < 0; : }
| m****v 发帖数: 84 | 8
try
#include
【在 p*****a 的大作中提到】 : 这个我试了下,好像还是不work
|
|