C
C#2y ago
fxduke

❔ C++ Help

The code is:
vector<string> s_split(string Str,string Seperator) {
vector<string> SplitStrings;
int ArrayIndex = 0;
for (int Index = 0; Index < Str.length(); Index++) {
char Character = Str.at(Index);
string SeperationCharacter = Str.substr(Index,Seperator.length());
if (SeperationCharacter == Seperator) {
SplitStrings.insert(SplitStrings.begin() + ArrayIndex++,"");
} else {
SplitStrings[ArrayIndex] += Character;
}
}
return SplitStrings;
}
vector<string> s_split(string Str,string Seperator) {
vector<string> SplitStrings;
int ArrayIndex = 0;
for (int Index = 0; Index < Str.length(); Index++) {
char Character = Str.at(Index);
string SeperationCharacter = Str.substr(Index,Seperator.length());
if (SeperationCharacter == Seperator) {
SplitStrings.insert(SplitStrings.begin() + ArrayIndex++,"");
} else {
SplitStrings[ArrayIndex] += Character;
}
}
return SplitStrings;
}
I'm trying to make something like lua has:
local bleh = "hello there how are you?"
local bleh2 = string.split(bleh," ")
print(bleh2[1]) -- "hello"
local bleh = "hello there how are you?"
local bleh2 = string.split(bleh," ")
print(bleh2[1]) -- "hello"
This was me trying to use the function:
int main() {
cout << "began\n";
vector<string> Hi = s_split("Hello there how are you doing today?"," ");
cout << Hi[0] << "\n";
cout << Hi[1] << "\n\n\n";
std::cout << "Hello World!\n";
return 0;
}
int main() {
cout << "began\n";
vector<string> Hi = s_split("Hello there how are you doing today?"," ");
cout << Hi[0] << "\n";
cout << Hi[1] << "\n\n\n";
std::cout << "Hello World!\n";
return 0;
}
The error I got was "Segment Fault". This is my 2nd day trying C++ so I'm mostly looking for what I've done wrong not how what I made was inefficient but I appreciate any feedback!
5 Replies
Pobiega
Pobiega2y ago
This is a C# discord.
fxduke
fxdukeOP2y ago
<a:animated_snaped:840999039922601984>
Pobiega
Pobiega2y ago
Please go to $cpp
MODiX
MODiX2y ago
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server