|
|
Home » Community » Newbie corner » String to std::string conversion
String to std::string conversion [message #32848] |
Wed, 15 June 2011 03:12  |
|
Hello.
I have a code:
std::string tempPath;
FileSel file;
{...}
tempPath = file[i]; <<== error C2593: 'operator =' is ambiguous
What would that possibly mean?
|
|
|
|
Re: String to std::string conversion [message #32850 is a reply to message #32849] |
Wed, 15 June 2011 05:35   |
|
Quote:
Quote: | C:\MyApps\proto1\main.cpp(42) : error C2872: 'String' : ambiguous symbol
could be 'c:\myapps\opencv22\opencv2/core/core.hpp(84) : std::string cv::String'
or 'c:\upp\uppsrc\core\String.h(294) : Upp::String'
C:\MyApps\proto1\main.cpp(42) : error C2440: 'const_cast' : cannot convert from 'Upp::String' to 'cv::String &'
Reason: cannot convert from 'Upp::String *' to 'cv::String *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
|
|
|
|
|
Re: String to std::string conversion [message #32852 is a reply to message #32850] |
Wed, 15 June 2011 07:30   |
|
Hi GaroRobe
Lances explanation about the const char* and std::string is correct. However, his solution is not, the const_cast can only change the constness of variable, not its type. Also, casting Upp::String to std::string is not a good idea anyway, as their internal representation probably differs.
Anyway, there is quite a number of possible solutions:
std::string tempPath;
FileSel file;
{...}
tempPath = ~file[i]; // converts the Upp::String to const char*
//OR
tempPath = file[i].Begin(); // basically the same as above
//OR
tempPath = std::string(~file[i],file[i].GetLength()); // create a new std::string with the same content and length
//OR
tempPath = std::string(~file[i],file[i].GetLength()); // again, more verbose variation on the previous line
Not that the first two solutions contain potential bug. If there are zero bytes ('\0') in the string, only part up until the first null would get copied. The last two solutions always copy the entire string properly, so I would recommend you to use one of those 
Best regards,
Honza
|
|
|
Re: String to std::string conversion [message #32853 is a reply to message #32852] |
Wed, 15 June 2011 07:37   |
|
Well, It compiles. But another problem arises.
My following lines are
tempFrame = imread( tempPath );
if( findChessboardCorners( tempFrame, checkboardSize, foundCorners )) <<=== Crashes here
{
frames.push_back( tempFrame );
imagePoints.push_back( foundCorners );
}
According to debugger, tempFrame is empty after imread() which is not what I expect.
BTW, that's why I am forced using STL types - most of parameters in OpenCV are std::something.
P.S.: Sorry, I know it's not about stl anymore - feels like I stumble at such topic shifts every time, but...
[Updated on: Wed, 15 June 2011 07:47] Report message to a moderator
|
|
|
Re: String to std::string conversion [message #32854 is a reply to message #32853] |
Wed, 15 June 2011 07:51   |
|
GaroRobe wrote on Wed, 15 June 2011 07:37 | BTW, that's why I am forced using STL types - most of parameters in OpenCV are std::something.
| Well, maybe we should better come up with some solution to use OpenCV with U++ types, instead of fixing every single use separately I'll have a look into it...
Honza
|
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 17:21:36 CEST 2025
Total time taken to generate the page: 0.00670 seconds
|
|
|