How to Break a Substring in C++

The C++ programming language is an intermediate-level, general-purpose programming language used for developing operating system applications, server and client applications, as well as video games. A substring in C++ contains a series of characters, and can contain several items of data. Breaking up substrings into smaller strings is important if you need each piece of data to be separated. You can break up a substring through your integrated development environment and a simple script.

Instructions

    • 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."

Related Searches:

References

Comments

Related Ads

Featured