C
C#17mo 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
Pobiega17mo ago
This is a C# discord.
fxduke
fxduke17mo ago
<a:animated_snaped:840999039922601984>
Pobiega
Pobiega17mo ago
Please go to $cpp
MODiX
MODiX17mo ago
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
Accord
Accord17mo 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
More Posts
❔ Need help with this part of a programming assignmenthello i am brand new to c# programming and i am stuck on this part of psuedocode and was wondering i✅ Make process believe it's a startup app?Hello! So I'm building an app that starts another app. The app in question seems to behave differen❔ Board Game (Marvel Champions) Gameplay Simulator - deep clone is very inefficientI have coded a program that simulates X games of Marvel Champions (a living card game by FFG). It wo❔ Problem of collections blocking when they shouldn't (BlockingCollection/ConcurrentQueue)Hello there, I have a problem with the producer-consumer patron in an application in net 6 (console❔ How do i run a c# programHello I wrote a new program in .txt file, how do i run this? It goes: Console WriteLine ()"Hello Wor✅ WPF SliderHello, I've bind my array of double to my slider but i do not know how to use the slider in order toCross Thread operation not valid: control 'CardStatusField' acessed from a thread other than the thr```c namespace Project1 { public partial class Form1 : Form { NFCReader NFC = new NF❔ ✅ Splitting string without allocationI'm writing a JsonConverter for Vector3 and I'd like to do this without allocating too much memory. ❔ How to correctly use Roslyn to parse RegionDirectiveTriviaSyntax in a project?I would like to ask a question about parsing syntax tree for #region preprocessor directive. For exa❔ How to rebuild searchable PDF to PDF with digital textI have already got searchable PDF, but that wasnt in text digital, it just an image but detected tex