[Assorted-commits] SF.net SVN: assorted: [853] sandbox/trunk/src/cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-06-06 00:27:09
|
Revision: 853 http://assorted.svn.sourceforge.net/assorted/?rev=853&view=rev Author: yangzhang Date: 2008-06-05 17:27:11 -0700 (Thu, 05 Jun 2008) Log Message: ----------- added boost lexical cast demo Added Paths: ----------- sandbox/trunk/src/cc/boost_lexical_cast.cc sandbox/trunk/src/cc/boost_tokenizer.cc Added: sandbox/trunk/src/cc/boost_lexical_cast.cc =================================================================== --- sandbox/trunk/src/cc/boost_lexical_cast.cc (rev 0) +++ sandbox/trunk/src/cc/boost_lexical_cast.cc 2008-06-06 00:27:11 UTC (rev 853) @@ -0,0 +1,31 @@ +#include <iostream> +#include <string> +#include <vector> +#include <boost/lexical_cast.hpp> + +using namespace boost; +using namespace std; + +int +main() +{ + string si("12345"); + int i = lexical_cast<int>(si); + cout << i << endl; + + // Doesn't work. +// string sb("true"); +// bool b = lexical_cast<bool>(sb); +// cout << b << endl; + + string sb("1"); + bool b = lexical_cast<bool>(sb); + cout << b << endl; + + // Doesn't work as expected. + stringstream ss("false"); + ss >> b; + cout << b << endl; + + return 0; +} Added: sandbox/trunk/src/cc/boost_tokenizer.cc =================================================================== --- sandbox/trunk/src/cc/boost_tokenizer.cc (rev 0) +++ sandbox/trunk/src/cc/boost_tokenizer.cc 2008-06-06 00:27:11 UTC (rev 853) @@ -0,0 +1,19 @@ +// Prints: +// This +// is +// a +// test + +#include<iostream> +#include<boost/tokenizer.hpp> +#include<string> + +int main(){ + using namespace std; + using namespace boost; + string s = "This is, a test"; + tokenizer<> tok(s); + for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ + cout << *beg << "\n"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |