gcc linker errors when using boost to_lower & trim - c++

I'm trying to use the boost library in my code but get the following linker errors under Sparc Solaris platform.
The problem code can essentially be summarised to:
#include <boost/algorithm/string.hpp>
std::string xparam;
...
xparam = boost::to_lower(xparam);
The linker error is:
LdapClient.cc:349: no match for `std::string& = void' operator
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:338: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:341: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:344: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
gmake: *** [LdapClient.o] Error 1
Any ideas?

boost::to_lower does not return a copy of the string, it operates on the variable passed into the function. For some examples, read this.
So no need to reassign:
boost::to_lower(xparam);
You will get an error because you are trying to assign the string to the value void.
If you want to make a copy of it, use the copy version:
std::string xparamLowered = boost::to_lower_copy(xparam);

boost::to_lower modifies the string in-place, it does not return a new string. This is sufficient:
boost::to_lower(xparam);
And your code doesn't compile because the return type of to_lower is void (as the error message says).

Related

Cannot compile with TSDuck in GCC 8.3.1

TSDuck Version 3.27.2438
GCC Version 8.3.1
Centos 7.9
I am trying to compile some code against TSDuck (RPM install version 3.27-2438). I get a compile error on UString.h. GCC seems to be unhappy with the use of a const_iterator in the erase function. As I understand it, this has been allowed since C++11 and should be implemented in GCC 8.3.1. Has anyone else run into this issue? It seems like a compiler bug, but I've also tried it in GCC 9.3.1 and gotten the same error.
Error:
/usr/include/tsduck/tsUString.h:2088:84: error: no matching function for call to ‘ts::UString::erase(std::basic_string<char16_t>::const_iterator&)’
iterator erase(const_iterator position) { return SuperClass::erase(position); }
^
In file included from /opt/rh/devtoolset-8/root/usr/include/c++/8/string:52,
from /opt/rh/devtoolset-8/root/usr/include/c++/8/stdexcept:39,
from /opt/rh/devtoolset-8/root/usr/include/c++/8/array:39,
from /opt/rh/devtoolset-8/root/usr/include/c++/8/tuple:39,
from /opt/rh/devtoolset-8/root/usr/include/c++/8/bits/unique_ptr.h:37,
from /opt/rh/devtoolset-8/root/usr/include/c++/8/memory:80,
from /workspaces/ts_reader/src/ts_reader/ts_reader.cpp:4:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4632:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
erase(size_type __pos = 0, size_type __n = npos)
^~~~~
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4632:7: note: no known conversion for argument 1 from ‘std::basic_string<char16_t>::const_iterator’ {aka ‘__gnu_cxx::__normal_iterator<const char16_t*, std::basic_string<char16_t> >’} to ‘std::basic_string<char16_t>::size_type’ {aka ‘long unsigned int’}
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4648:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char16_t*, std::basic_string<char16_t> >; typename _Alloc::rebind<_CharT>::other::pointer = char16_t*]’
erase(iterator __position)
^~~~~
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4648:7: note: no known conversion for argument 1 from ‘__normal_iterator<const char16_t*,[...]>’ to ‘__normal_iterator<char16_t*,[...]>’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4668:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char16_t*, std::basic_string<char16_t> >; typename _Alloc::rebind<_CharT>::other::pointer = char16_t*]’
erase(iterator __first, iterator __last);
^~~~~
Check that you are using the C++11 ABI.
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
_GLIBCXX_USE_CXX11_ABI
Defined to the value 1 by default. Configurable via --disable-libstdcxx-dual-abi and/or --with-default-libstdcxx-abi. ABI-changing. When defined to a non-zero value the library headers will use the new C++11-conforming ABI introduced in GCC 5, rather than the older ABI introduced in GCC 3.4. This changes the definition of several class templates, including std:string, std::list and some locale facets. For more details see Dual ABI.

Why boost::replace_all_copy is not working? C++

I am trying to make working code to replace text of line. Using boost_1_64_0 .
getline (ifs, line);
cout << line << endl;
// 1.
boost::replace_all(line, "abc", "hij");
boost::replace_all(line, "def", "klm");
// 2.
line = boost::replace_all_copy
boost::replace_all_copy<string>
(
("abc def abc def", "abc", "hij")
, "def"
, "klm"
);
I am getting these errors:
main.cpp||In function 'int main()':|
main.cpp|37|error: no match for 'operator=' in 'line = boost::algorithm::replace_all_copy'|
main.cpp|37|note: candidates are:|
\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|543|note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]|
mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|543|note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::basic_string<char>&'|
mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|551|note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]|
mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|551|note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const char*'|
mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|562|note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]|
mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|562|note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'char'|
main.cpp|38|error: expected ';' before 'boost'|
main.cpp|53|error: expected '}' before 'else'|
Why the error happens or how can I correct them?
You have written obviously broken code:
line = boost::replace_all_copy boost::replace_all_copy<string>(...)

error while working with boost::sregex_token_iterator

I want to search for a regular expression and print it with a color. I used boost::sregex_token_iterator to do this. this is my code
boost::regex re("ab.");
string s="";
string buf;
string infile("retest.txt");
//string color="green";
ifstream in(infile.c_str());
int lcount=0;
while (getline(in,buf))
{
boost::sregex_token_iterator p(buf.begin(), buf.end(), re, 0);
boost::sregex_token_iterator end;
lcount++;
cout <<"line : "<<lcount<<endl;
for (;p != end;++p)
{
string m(p->first, p->second);
cout<< m <<endl;
//cout <<*(p->first)<<endl;
//cout <<*(p->second)<<endl;
//unsigned int pos = buf.find(m);
buf = buf.insert(p->first,"\e[0;32m");
buf = buf.insert(p->second+m.length()+7,"\e[0m");
}
cout<<"\n";
s.append(buf);
s.append("\n");
}
in.close();
cout <<"s is: "<<s<<endl;
return 0;
}
but I get this error :
In file included from /usr/include/boost/config.hpp:35:0,
from /usr/include/boost/regex/config.hpp:53,
from /usr/include/boost/regex.hpp:28,
from main3.cc:3:
/usr/include/boost/config/compiler/gcc.hpp:92:7: warning: #warning "Unknown compiler version - please run the configure tests and report the results" [-Wcpp]
main3.cc: In function âint main(int, char**)â:
main3.cc:36:40: error: no matching function for call to âstd::basic_string::insert(const __gnu_cxx::__normal_iterator >&, const char [8])â
main3.cc:36:40: note: candidates are:
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1182:7: note: void std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator >; typename _Alloc::rebind<_CharT>::other::pointer = char*; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1182:7: note: candidate expects 3 arguments, 2 provided
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1199:9: note: template void std::basic_string::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1199:9: note: template argument deduction/substitution failed:
main3.cc:36:40: note: cannot convert âp.boost::regex_token_iterator::operator-><__gnu_cxx::__normal_iterator >, char, boost::regex_traits, std::allocator >()->boost::sub_match<__gnu_cxx::__normal_iterator > >::.std::pair<__gnu_cxx::__normal_iterator >, __gnu_cxx::__normal_iterator > >::firstâ (type âconst __gnu_cxx::__normal_iterator >â) to type âstd::basic_string::iterator {aka __gnu_cxx::__normal_iterator >}â
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1230:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1230:7: note: no known conversion for argument 1 from âconst __gnu_cxx::__normal_iterator >â to âstd::basic_string::size_type {aka unsigned int}â
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1252:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1252:7: note: candidate expects 4 arguments, 2 provided
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:55:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.tcc:361:6: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.tcc:361:6: note: candidate expects 3 arguments, 2 provided
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1293:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1293:7: note: no known conversion for argument 1 from âconst __gnu_cxx::__normal_iterator >â to âstd::basic_string::size_type {aka unsigned int}â
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1316:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1316:7: note: candidate expects 3 arguments, 2 provided
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1334:7: note: std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator >; typename _Alloc::rebind<_CharT>::other::pointer = char*]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1334:7: note: no known conversion for argument 1 from âconst __gnu_cxx::__normal_iterator >â to âstd::basic_string::iterator {aka __gnu_cxx::__normal_iterator >}â
main3.cc:37:51: error: no matching function for call to âstd::basic_string::insert(__gnu_cxx::__normal_iterator >, const char [5])â
main3.cc:37:51: note: candidates are:
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1182:7: note: void std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator >; typename _Alloc::rebind<_CharT>::other::pointer = char*; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1182:7: note: candidate expects 3 arguments, 2 provided
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1199:9: note: template void std::basic_string::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1199:9: note: template argument deduction/substitution failed:
main3.cc:37:51: note: cannot convert âp.boost::regex_token_iterator::operator-><__gnu_cxx::__normal_iterator >, char, boost::regex_traits, std::allocator >()->boost::sub_match<__gnu_cxx::__normal_iterator > >::.std::pair<__gnu_cxx::__normal_iterator >, __gnu_cxx::__normal_iterator > >::second.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+ >((* &((__gnu_cxx::__normal_iterator >::difference_type)m.std::basic_string<_CharT, _Traits, Alloc>::length, std::allocator >())))._gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+ >((* &7))â (type â__gnu_cxx::__normal_iterator >â) to type âstd::basic_string::iterator {aka __gnu_cxx::__normal_iterator >}â
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1230:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1230:7: note: no known conversion for argument 1 from â__gnu_cxx::__normal_iterator >â to âstd::basic_string::size_type {aka unsigned int}â
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1252:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1252:7: note: candidate expects 4 arguments, 2 provided
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:55:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.tcc:361:6: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.tcc:361:6: note: candidate expects 3 arguments, 2 provided
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:54:0,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
from main3.cc:1:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1293:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1293:7: note: no known conversion for argument 1 from â__gnu_cxx::__normal_iterator >â to âstd::basic_string::size_type {aka unsigned int}â
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1316:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1316:7: note: candidate expects 3 arguments, 2 provided
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1334:7: note: std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator >; typename _Alloc::rebind<_CharT>::other::pointer = char*]
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:1334:7: note: no known conversion for argument 1 from â__gnu_cxx::__normal_iterator >â to âstd::basic_string::iterator {aka __gnu_cxx::__normal_iterator >}â
I know that the type of p->first is not the one which insert function accepts. but I don't know how to convert these to each other.
The issue might be your usage of std::string::insert. I can't see an insert(iterator, string) version among it's numerous overloads.
You might want to call desired version by explicitly stating length of char array:
void insert (iterator p, size_t n, char c)
The problem seems to be that boost is configured for use with a different version of the compiler rather than the one you are currently using.
Could you add the details of how you compiled it as well?

Trying to build muParser: error: explicit instantiation of 'std::basic_ostream but no definition available

Im trying to build muParser on the mac, it worked until I upgraded XCode to 4.4 which updated gcc. Now I get the following line of code generating the error which I don't understand:
mu::console() << _T(" \"") << val.GetAsString() << _T("\" ");
../muparser/src/muParserBase.cpp:1823: instantiated from here
../muparser/src/muParserBase.cpp:1823: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
../muparser/src/muParserBase.cpp: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
../muparser/src/muParserBase.cpp:1823: instantiated from here
../muparser/src/muParserBase.cpp:1823: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
../muparser/src/muParserBase.cpp: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
../muparser/src/muParserBase.cpp:1823: instantiated from here
../muparser/src/muParserBase.cpp:1823: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
../muparser/src/muParserBase.cpp: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
../muparser/src/muParserBase.cpp:1823: instantiated from here
../muparser/src/muParserBase.cpp:1823: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
mu::console() is define as:
inline std::ostream& console()
{
return std::cout;
}
_T is #define _T(x) x
and GetAsString
const TString& GetAsString() const
{
return m_strTok;
}
TString is a std::string
It is the call to GetAsString that causes the problem. Any idea how to fix it?
Add these two lines to your .pro file and the error will go away:
QMAKE_CFLAGS_X86_64 += -mmacosx-version-min=10.7
QMAKE_CXXFLAGS_X86_64 = $$QMAKE_CFLAGS_X86_64
It looks like you are linking the wrong standard library or including the wrong C++ includes. You will want to make sure your include path c++ headers matches the standard library you are linking.
If you post your build file, I can help see if there is a mismatch.
When I upgraded to XCode 4.4.x, the Command Line Tools were removed. In XCode, I wend to XCode > Preferences, selected the Downloads tab, and re-downloaded "Command Line Tools" and then things started to work again. Maybe this will fix your problem too?

Using push_back on a vector of strings - C++

I am trying to use push_back on a vector of strings in C++. How can I push a single character on to the vector? Currently, I have tried the following, all without success:
Initialized a string (tried to) with the character.
Code
string str(main_string[0]);
vector_string.push_back(str);
Tried to invoke strcpy and thus copy contents. Const-ness seems to get in the way.
Code
string str;
strcpy(main_string[0], str.c_str());
vector_string.push_back(str);
Any more suggestions/ideas are most welcome.
Edit: The error logs are as follows:
test_push.C: In function ‘void test_push(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::string)’:
test_push.C:50: error: no matching function for call to ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char&)’
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:220: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(typename _Alloc::rebind<_CharT>::other::size_type, _CharT, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:213: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>] <near match>
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:206: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, typename _Alloc::rebind<_CharT>::other::size_type, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:194: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:184: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:170: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:178: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.h:2147: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
test_push.C:61: error: conversion from ‘char’ to non-scalar type ‘std::string’ requested
test_push:90: error: no matching function for call to ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char&)’
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:220: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(typename _Alloc::rebind<_CharT>::other::size_type, _CharT, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:213: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>] <near match>
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:206: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, typename _Alloc::rebind<_CharT>::other::size_type, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
More info: In this function, either the entire string or just the first letter is pushed in to the vector based on its contents. So, in a way, I am looking for some function that converts a char into a C++ style std::string (to make it acceptable to a vector).
Thanks,
Sriram
You can also initialize with one character like this.
string str(1,main_string[0]);
vector_string.push_back(str);
You can add the character directly via an appropriate string constructor:
vector_string.push_back(string(1, main_string[0]));
EDIT: Removed alternate solution after realising it duplicates #Tim's.
no need for strcpy for a single character.
string str ("x");
str[0] = main_string[0];
vector_string.push_back(str);