boost library lexical_cast cann't be compiled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux