c++ compere string code example

Example 1: c++ string

#include <string>

std::string myString = "Hello, World!";

Example 2: c++ recorrer string

std::string Find(std::string const& palabra, std::string const& delim, int & init)
{
  int end = palabra.find(delim, prev);
  std::string toReturn = palabra.substr(init, end - init);
  init = end;
  return toReturn;
}

std::string s = "Hola-perro-Cosa";
int init = 0;
std::string string1 = Find(s, "-", init);
std::string string2 = Find(s, "-", init);
std::string string3 = Find(s, "-", init);

Tags:

Cpp Example