Se afișează postările cu eticheta string. Afișați toate postările
Se afișează postările cu eticheta string. Afișați toate postările

marți, 14 martie 2017

npos c++ example

c++ > <string> > npos 

// bad/missing length/position

An unsigned integral value initialized to –1 that indicates either "not found" or "all remaining characters" when a search function fails.

static const size_type npos = -1;  

Example

#include "stdafx.h"

#include <iostream>
#include <string>

int main()
{
       std::string input = "input string";

       if (input.find('b') == std::string::npos)
       {
              std::cout << "no 'b' found in 'input string'\n";
       }

       if (input.find('p') != std::string::npos)
       {
              std::cout << "'p' found in 'input string'\n";
       }

}