|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72062 - trunk/libs/wave/samples/cpp_tokens
From: hartmut.kaiser_at_[hidden]
Date: 2011-05-21 16:23:48
Author: hkaiser
Date: 2011-05-21 16:23:47 EDT (Sat, 21 May 2011)
New Revision: 72062
URL: http://svn.boost.org/trac/boost/changeset/72062
Log:
Wave: Fixing example to behave properly if input is not terminated with a newline
Text files modified:
trunk/libs/wave/samples/cpp_tokens/cpp_tokens.cpp | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
Modified: trunk/libs/wave/samples/cpp_tokens/cpp_tokens.cpp
==============================================================================
--- trunk/libs/wave/samples/cpp_tokens/cpp_tokens.cpp (original)
+++ trunk/libs/wave/samples/cpp_tokens/cpp_tokens.cpp 2011-05-21 16:23:47 EDT (Sat, 21 May 2011)
@@ -52,16 +52,20 @@
return 1;
}
-// read the file to analyse into a std::string
+// read the file to analyse into a std::string
ifstream infile(argv[1]);
string teststr;
if (infile.is_open()) {
infile.unsetf(std::ios::skipws);
- string line;
- for (getline(infile, line); infile.good(); getline(infile, line)) {
- teststr += line;
- teststr += '\n';
- }
+#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
+ // this is known to be very slow for large files on some systems
+ copy (std::istream_iterator<char>(infile),
+ std::istream_iterator<char>(),
+ std::inserter(teststr, teststr.end()));
+#else
+ teststr = std::string(std::istreambuf_iterator<char>(infile.rdbuf()),
+ std::istreambuf_iterator<char>());
+#endif
}
else {
teststr = argv[1];
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk