This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

boost library lexical_cast cann't be compiled


Dear advanced g++ programers:

  I tried to copy/test a piece simple boost library's lexical_cast
c++ code from book c++Cookbook, page 122, example 3-2.
----------------------------------------------------------
// Example 3-2. Using lexical_cast

#include <iostream>
#include <string>
#include "boost/lexical_cast.hpp" /* I comple this program
                                   * right above directory boost
                                   */
     //  <boost/lexical_cast.hpp>

using namespace std;

int main() {
   string str1 = "750";
   string str2 = "2.71";
   string str3 = "0x7FFF";
   try {
     cout << boost::lexical_cast<int>(str1) << endl;
     cout << boost::lexical_cast<double>(str2) << endl;
     cout << boost::lexical_cast<int>(str3) << endl;
   }
   catch (boost::bad_lexical_cast& e) {
     cerr << "Bad cast: " << e.what() << endl;
   }
}
-----------------------------------------------------
---------------

eric@eric-laptop:~/boost1/boost_1_46_1$ g++ usinglexicast.cpp
usinglexicast.cpp: In function âint main()â:
usinglexicast.cpp:16:34: error: âstr3â cannot appear in a
constant-expression
usinglexicast.cpp:16:21: error: no match for âoperator<<â in âstd::cout
<< lexical_cast<<expression error> >â
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/ostream:108:7: note: candidates are: std::basic_ostream<_CharT,
_Traits>::__ostream_type& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT,
_Traits>::__ostream_type& (*)(std::basic_ostream<_CharT,
_Traits>::__ostream_type&)) [with _CharT = char, _Traits =
std::char_traits<char>, std::basic_ostream<_CharT,
_Traits>::__ostream_type = std::basic_ostream<char>]
------------------------------------------------------------
This is only beginning portion of more longer g++ compile errors.
plz help
thanks a lot in advance
Eric


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]