How to Break a Substring in C++
- 1). Launch the integrated environment of your choice and open your C++ substring by clicking "File" and "Open."
- 2). Copy and paste the following code into the command line:
#include <iostream>
using namespace std;
void split_string(char *orig, char *first, char *second, int pos) {
char newline = '\n';
int x;
int counter = pos;
for (x = 0; 1; x++) {
if (orig[counter] == newline) break;
second[x] = orig[counter];
counter++;
}
second[x] = newline;
for (x = 0; x < pos; x++) {
first[x] = orig[x];
}
first[pos] = newline;
}
int main() {
char *s = "An array of characters.\n";
char *t = (char *) calloc(5, sizeof s);
char *u = (char *) calloc((sizeof t)-5, sizeof s);
split_string(s,t,u,5);
cout << "first string " << t;
cout << "second string " << u;
return 0;
} - 3). Click "File" and "Save As." Save your file as an executable file, or ".exe." Click "Save."