I have been working on a few projects and needed a method similar to pythons string.split(). I decided to make a reusable piece of code and export it as a .dll, the code is below:
std::vector<std::string> Editor::StringHandler::Split(std::string data, std::string tokens)
std::vector<std::string> returnList;
std::string temp="";
bool found=false;
for (auto i : data)
{
found = false;
for (auto token : tokens)
{
found = (i == token);
if (found && temp.length() > 0)
{
returnList.push_back(temp);
temp = "";
}
if (found)
{
break;
}
}
if (!found)
{
temp += i;
}
}
if (!found)
{
returnList.push_back(temp);
}
return returnList;
}
The code itself works fine if compiled into and executable and run; but if compiled into a dll and used in another project I get a run time error of access violation. I've tried using both returnList.reserve(data.length());
and temp.reserve(data.length());
but no avail. The call stack shows
> msvcr110.dll!memcpy(unsigned char * dst, unsigned char * src, unsigned long count) Line 750 Unknown
Render Engine V1.exe!wmain(int argc, wchar_t * * argv) Line 40 C++`
Render Engine V1.exe!__tmainCRTStartup() Line 533 C`
Render Engine V1.exe!wmainCRTStartup() Line 377 C
The code used to call the function is:
std::vector<std::string> vowels, novowels;
std::string info("test snippet of data");
std::string tokens("aeiou ");
vowels = Editor::StringHandler::Split(info);
novowels = Editor::StringHandler::Split(info, tokens);
for (auto s : vowels)
{
OutputLog(s.c_str());
}
std::cout << std::endl;
for (auto i : novowels)
{
OutputLog(i.c_str());
}
Any help as to why this is happening/how to fix it?