Hi all, I'm transferring a c++ app that works under windows , in ubuntu Linux 32bit with GCC version 5.4.0 20160609. I'm using poco c++ libraries as well as aws kinesis. However I get an error that I didn't get in visual studio building. The code I'm using is the following:
Aws::String accessToken = "";
Aws::String sk = "";
Aws::String skt = "";
StringTokenizer tokenizer(sessionToken, "\t", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
if (tokenizer.count() > 0)
{
accessToken = tokenizer[2];
sk = tokenizer[3];
skt = tokenizer[4];
}
The constructor of StringTokenizer is StringTokenizer(const std::string& str, const std::string& separators, int options = 0); while from Awsstring.h we have using String = std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > >;
The error I get is
no match for ‘operator=’ (operand types are ‘Aws::String {aka std::cxx11::basic_string
I assume that it has to be a const problem. In the operator= overload the parameter should be const. Do you agree with the above and what would you suggest for overcoming the error? Is it possible for the GCC compiler to be the root cause since I didn't deal with it under visual studio.
It's probably not a const issue. From a strict point of view, Aws::String is a distinct and incompatible type from std::string if custom memory management is enabled (and it sounds like it is). There are a couple of approaches you could try to work around this:
(1) explicitly turn off custom memory management (-DCUSTOM_MEMORY_MANAGEMENT=0 on the cmake command line)
(2) add a constructor overload that takes an Aws::String or a const char *. If StringTokenizer is not under your control then this option will not work.
(3) Convert to and from Aws::String to std::string whenever you need to use this object
Hi again and thanks for the quick reply I changed the tokenizer[2] into tokenizer[2].c_str(); and it worked
(3) Convert to and from Aws::String to std::string whenever you need to use this object
What does convert to and from Aws::String and std::string mean? In other words, what is the recommended way of converting between the two?
If you have a std::string you want to pass to an Aws function, construct an Aws::String from it
std::string s{"whatever"};
Aws::String aws_s(s.c_str(), s.size());
Aws::SomeFunction(aws_s);
If you got an Aws::String from an Aws function, construct a std::string from it:
Aws::String const& aws_s = Aws::SomeFunction();
std::string s(aws_s.c_str(), aws_s.size());
Both of these perform a copy of the string content, unfortunately.
Aws::String aws_s(std_string.c_str()) would measure the string length with strlen(), an information already contained in the std::string object.
Awesome, thanks @Bu11etmagnet
Most helpful comment
If you have a
std::stringyou want to pass to an Aws function, construct anAws::Stringfrom itIf you got an
Aws::Stringfrom an Aws function, construct astd::stringfrom it:Both of these perform a copy of the string content, unfortunately.
Aws::String aws_s(std_string.c_str())would measure the string length with strlen(), an information already contained in the std::string object.