frage zu strings
-
Tachyon schrieb:
Aha...

ok, hier ist sie:
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2229) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2229) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2229) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2229) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2029) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2029) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2029) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2029) : see declaration of 'std::operator +'
1>z:\0d\sajh0867\windows\my documents\visual studio 2008\projects\06_2_mehrdimfelder\main.cpp(37) : error C2676: binary '+' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operatorknivil schrieb:
Frage bitte nicht warum!
das wäre jetzt meine nächste frage gewesen... wenn man schon mal dabei ist += zu überladen, kann man doch auch gleich...
Tachyon schrieb:
Klar gibt es die. Allerdings nicht als Member von std::string sondern global definiert.
ein guter link, nur leider versteh ich anscheinend nicht, was da steht.

wenn ich mir die signatur anschaue, müsste doch zumindest sowas klappen:const string a = "a"; const string b = "b"; string c = a + b;tuts aber nicht, fehlermeldung siehe oben
-
Welche Header hast Du eingebunden, und welche using-Direktiven benutzt Du?
-
#include <iostream> #include <cstdlib> using namespace std;
-
Wie wärs denn noch mit
#include <string>
-
Tachyon schrieb:
Wie wärs denn noch mit
#include <string>
lol ...
-
kaum macht man's richtig, funktioniert plötzlich alles.
nee ma ernsthaft, ich versteh das nicht. ich kann doch die klasse string einwandfrei benutzen, ohne <string> eingebunden zu haben? wieso geht operator+= ohne das #include, operator+ aber nicht? oder anders, warum komm ich an die memberfunktionen (und den ktor?) von string ran, und warum komm ich an, ähm, global definierte funktionen (von <string>?) nicht heran?
-
Hackfresser schrieb:
kaum macht man's richtig, funktioniert plötzlich alles.
nee ma ernsthaft, ich versteh das nicht. ich kann doch die klasse string einwandfrei benutzen, ohne <string> eingebunden zu haben? wieso geht operator+= ohne das #include, operator+ aber nicht? oder anders, warum komm ich an die memberfunktionen (und den ktor?) von string ran, und warum komm ich an, ähm, global definierte funktionen (von <string>?) nicht heran?
Teile von
std::stringziehst Du Dir in diesem Fall (das ist compilerspezifisch) überiostreammit an. Darin fehlen aber die global überladenen Operatoren. Die sind wiederum instringdefiniert. Dasstd::basic_string-Template ist beim MS-Compiler z.B. im header xstring definiert. Und der wird irgendwo ganz unten auch in den Streamklassen benutzt.
-
hm stimmt, sonst könnte man ja keine strings an streams schicken
und warum haben die den operator+= als member definiert, den operator+ aber global?
-
Hackfresser schrieb:
und warum haben die den operator+= als member definiert, den operator+ aber global?
Schau mal im Artikel-Forum (*Werbung mach*), da gibts n Artikel über Operatorüberladung in C++ (Teil 1), in dem darauf engegangen wird warum der eine Operator als freie Funktion, der andere als Klassenmethode überladen wird.
Btw. richtig global ist dor op+ auch nicht, sondern im namespace std.
-
ok danke ich schau mal