1 2
|
sring input = "jae.kim@jhykima, I like icecream & water, #coding.";
cin >> input;
|
You initialize the string and then overwrite it immediately
using namespace std;
That's a bad habit because it pollutes the global namespace.
If you really want to write cout, cin, string and vector like that you should only import std::cout, std::cin, std::string and std::vector, not the whole namespace.
As an alternative you could import the std::namespace in the main function, then it won't pollute the global namespace but only the scope of main.
You got lucky here, and you'll be lucky most of the time but there are several functions in the std::namespace that will shadow yours if you want to make your own version of it, for example if you want to write your own swap, sqrt or similar simple functions.
1 2 3 4 5 6 7 8 9
|
for (int i = 0; i < symbols.length (); i++)
{
size_t found = input.find_first_of (symbols[i]);
if (found != string::npos)
{
symbol_index.push_back (found);
j++;
}
}
|
|
std::string has a function called find_first_of where you can search the string for ANY of the characters.
You could just write symbols.find_first_of() and if found you could search for that character in input.
like that:
1 2 3 4 5 6
|
std::size_t found = 0;
do {
found = input.find_first_of(symbols);
if(found != std::string::npos)
symbol_index.push_back(symbols[ symbols.find_first_of(input[found]) ]);
} while(found != std::string::npos);
|
This should give you a performance boost