Difference between revisions of "CPP/Strings/SingleCharacterTag"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==SingleCharacterTag.cpp== <source lang="cpp"> #include <iostream> #include <string> int main() { size_t firstPos = 0, secondPos; std::string temp = "some text a <tag> and m…')
(No difference)

Revision as of 18:14, 28 June 2010

SingleCharacterTag.cpp

#include <iostream>
#include <string>
 
int main()
{
  size_t firstPos = 0, secondPos;
  std::string temp = "some text a <tag> and more text";
  std::string sub;
  if ((firstPos = temp.find_first_of("<", firstPos)) != std::string.npos)
  {
    if ((secondPos = temp.find_first_of(">", firstPos + 1)) != std::string.npos)
    {
      sub = temp.substr(firstPos, (secondPos - firstPos + 1))
    }
  }
 
  return 0;
}