using namespace std;
#include <iostream>
#include <vector>
#include <string>
std::vector<std::string> DIFSplitStringByNumber(const std::string& str, int splitLength)
{
int NumSubstrings = str.length() / splitLength;
std::vector<std::string> ret;
for (auto i = 0; i < NumSubstrings; i++)
{
ret.push_back(str.substr(i * splitLength, splitLength));
}
// If there are leftover characters, create a shorter item at the end.
if (str.length() % splitLength != 0)
{
ret.push_back(str.substr(splitLength * NumSubstrings));
}
return ret;
}
int main() {
std::cout << DIFSplitStringByNumber("hello", 2);
}
This is my code. I found it on another question on how to split a string by every nth character. What I want to do now is to print out the split character but I dont know how. I know cout doesn't work.