Skip to content

Commit

Permalink
Updated version using StrTk from Arash Partow
Browse files Browse the repository at this point in the history
It removes the resize call overhead in the loop that was introduced when
counting was added.
  • Loading branch information
daveisfera authored and tobbez committed Apr 18, 2015
1 parent b2a49ef commit fafa73d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions split7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <ctime>
#include <vector>
#include <iterator>

#include "strtk.hpp"

Expand All @@ -23,17 +24,21 @@ int main()
std::size_t numWords = 0;
std::size_t numChars = 0;

spline.reserve(100);

while(std::cin)
{
spline.clear();

std::getline(std::cin, input_line);
spline.resize(100);
std::size_t numFields = strtk::split(delimiter,
input_line,
spline.begin());
spline.resize(numFields);
numWords += numFields;

numWords += strtk::split(delimiter,
input_line,
std::back_inserter(spline));

for (std::vector<StrLimits>::const_iterator iter = spline.begin(); iter != spline.end(); ++iter)
numChars += iter->second - iter->first;

count++;
};

Expand Down

0 comments on commit fafa73d

Please sign in to comment.