CPP/Boost/LexicalCast

From ProgrammingExamples

< CPP
Jump to: navigation, search

LexicalCast.cpp

#include <iostream>
 
#include <boost/lexical_cast.hpp>
 
int main(int argc, char* argv[])
{
  std::string stringNumber = "2.0";
  float floatNumber = boost::lexical_cast<float>(stringNumber);
 
  std::cout << floatNumber << std::endl;
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(LexicalCast)
 
FIND_PACKAGE(Boost)
 
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})
 
ADD_EXECUTABLE(LexicalCast LexicalCast.cpp)
Personal tools