+ cannot add two pointers, most elegant solution ?
-
Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.
if (GetDriveType(drv) == DRIVE\_FIXED) { GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace); itoa(GetTickCount()/1000%60,ds,10); itoa(GetTickCount()/1000%60,fs,10); string temp = "test " + ds + " dasd" + fs; }
error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !
-
Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.
if (GetDriveType(drv) == DRIVE\_FIXED) { GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace); itoa(GetTickCount()/1000%60,ds,10); itoa(GetTickCount()/1000%60,fs,10); string temp = "test " + ds + " dasd" + fs; }
error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !
ALLERSLIT wrote:
Open for any suggestions, greetings !
You did not show how
ds
andfs
were declared, but one way might be:string temp = string("test ") + ds + string(" dasd") + fs;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
ALLERSLIT wrote:
Open for any suggestions, greetings !
You did not show how
ds
andfs
were declared, but one way might be:string temp = string("test ") + ds + string(" dasd") + fs;
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Does not work out for me. Getting theese errors:
Does not work out for me.
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2203) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2003) : see declaration of 'std::operator +'
\test\main.cpp(18) : error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator -
Does not work out for me. Getting theese errors:
Does not work out for me.
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2203) : see declaration of 'std::operator +'
\test\main.cpp(18) : 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 'char [5]'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2003) : see declaration of 'std::operator +'
\test\main.cpp(18) : error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator -
Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.
if (GetDriveType(drv) == DRIVE\_FIXED) { GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace); itoa(GetTickCount()/1000%60,ds,10); itoa(GetTickCount()/1000%60,fs,10); string temp = "test " + ds + " dasd" + fs; }
error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !
-
Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.
if (GetDriveType(drv) == DRIVE\_FIXED) { GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace); itoa(GetTickCount()/1000%60,ds,10); itoa(GetTickCount()/1000%60,fs,10); string temp = "test " + ds + " dasd" + fs; }
error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !
Hi, This would do the same without ugly and dangerous multiple additions of
std::string
andconst char*
:#include <sstream>
// ...
if (GetDriveType(drv) == DRIVE_FIXED)
{
GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
std::ostringstream oss;
oss << "test " << GetTickCount() / 1000 % 60;
oss << " dasd " << GetTickCount() / 1000 % 60 << std::ends;
std::string temp = oss.str();
}cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
modified on Saturday, October 30, 2010 2:51 AM