Home » Community » Newbie corner » errors re strings
errors re strings [message #46364] |
Fri, 29 April 2016 08:46  |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
(647): error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator <char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<ch
ar> &)': cannot convert argument 1 from 'Upp::String' to 'const std::basic_string<char,std::char_traits<char>,std::allocator <char>> &'
A previous topic similar to this error was only when compiling with MINGW
This error is when recompiling an older app with upp 7901 and even with MSC15
Has the changes that causes this with C++11? or was this changes in the upp code?
Do I need to change all the 'string' to upp::String or is there an easier way ??
There are several apps that I may run into with this error as they are updated from a few years back.
here are a few lines of code:
line 647 string Min (Tm, 2,2);
string Sec (Tm, 4,2);
String Tmz = Hr + ":" + Min + ":" + Sec;
count<<=Tmz;
Neil
[Updated on: Fri, 29 April 2016 09:01] Report message to a moderator
|
|
|
Re: errors re strings [message #46365 is a reply to message #46364] |
Fri, 29 April 2016 10:44   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
std::string and Upp::String are two completely different classes.
So the question is, why do you even use std::string in U++ application (or the other way around, why don't you stick solely to std::string, if you want to keep usage of U++ low and having that part of source usable without U++ Core too).
If your app is strongly U++ dependent, I would go for Upp::String only (except places where you call some external library, which has input as std::string, at that single point I would convert the String to string, but otherwise I would keep internally everything in String).
I often write clean C++ libraries in TheIDE (to be compiled on phone platforms, so I don't use Upp at all), then I use std::string only.
Your mixed way is certainly possible too, but I think it's not giving you any advantage, just confusing.
|
|
|
Re: errors re strings [message #46366 is a reply to message #46364] |
Fri, 29 April 2016 10:59   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi,
the conversion from Upp::String to std::string is explicit by the function member ToStd()
String s_upp;
std::string s_std = s_upp.ToStd();
IMO the easier way is to avoid std::string, Upp::String is simpler, faster.
here a solution for this error:
String Min = Tm.Mid(2,2);
String Tmz = Hr + ":" + Min + ":" + Tm.Mid(4,2);
count<<=Tmz;
regards
omari.
|
|
|
Re: errors re strings - SOLVED [message #46367 is a reply to message #46365] |
Fri, 29 April 2016 13:24   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Hi mr ped thanks I did not know there was such a difference and that mixing them could lead to errors,
Most of my apps depend on several header .h 'apps' so I will try and remember what could cause problems.
I have no preference for which string or String, whatever works but I will try to use just one.
mr_ped wrote on Fri, 29 April 2016 01:44std::string and Upp::String are two completely different classes.
So the question is, why do you even use std::string in U++ application (or the other way around, why don't you stick solely to std::string, if you want to keep usage of U++ low and having that part of source usable without U++ Core too).
If your app is strongly U++ dependent, I would go for Upp::String only (except places where you call some external library, which has input as std::string, at that single point I would convert the String to string, but otherwise I would keep internally everything in String).
I often write clean C++ libraries in TheIDE (to be compiled on phone platforms, so I don't use Upp at all), then I use std::string only.
Your mixed way is certainly possible too, but I think it's not giving you any advantage, just confusing.
Neil
[Updated on: Thu, 05 May 2016 09:30] Report message to a moderator
|
|
|
Re: errors re strings - [message #46368 is a reply to message #46366] |
Fri, 29 April 2016 13:33   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
omari wrote on Fri, 29 April 2016 01:59Hi,
the conversion from Upp::String to std::string is explicit by the function member ToStd()
String s_upp;
std::string s_std = s_upp.ToStd();
IMO the easier way is to avoid std::string, Upp::String is simpler, faster.
here a solution for this error:
String Min = Tm.Mid(2,2);
String Tmz = Hr + ":" + Min + ":" + Tm.Mid(4,2);
count<<=Tmz;
Hi Omari Thanks Your solution code worked first time and I appreciate the explanation, that is how I learn the most, code that works and then the reason behind it.
Neil
[Updated on: Wed, 25 May 2016 12:02] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 30 20:28:27 CEST 2025
Total time taken to generate the page: 0.00998 seconds
|