How to find the first occurrence of character in string with C++

1 Answer

0 votes
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s = "c++ c c# java python";

	size_t pos = s.find_first_of(' ');

	cout << pos << endl;

	cout << s.substr(0, pos) << endl;
	cout << s.substr(pos + 1) << endl;

	return 0;
}

/*
run:

3
c++
c c# java python

*/

 



answered Feb 25, 2017 by avibootz
...