Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Created January 31, 2018 18:02
Show Gist options
  • Select an option

  • Save sonOfRa/8585db89bb556bdf0cf414d1945c0478 to your computer and use it in GitHub Desktop.

Select an option

Save sonOfRa/8585db89bb556bdf0cf414d1945c0478 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
int main()
{
std::string line = "This string has several words";
std::istringstream iss(line);
std::vector<std::string> words((std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());
std::cout << words.size() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment