C++ check if string is space or null

后端 未结 6 1255
死守一世寂寞
死守一世寂寞 2021-01-13 04:38

Basically I have string of whitespace \" \" or blocks of whitespace or \"\" empty in some of the lines of the files and I would

6条回答
  •  花落未央
    2021-01-13 05:26

    You don't have a nullstring "in some of the lines of the files".

    But you can have an empty string, i.e. an empty line.

    You can use e.g. std::string.length, or if you like C better, strlen function.

    In order to check for whitespace, the isspace function is handy, but note that for char characters the argument should be casted to unsigned char, e.g., off the cuff,

    bool isSpace( char c )
    {
        typedef unsigned char UChar;
        return bool( ::isspace( UChar( c ) ) );
    }
    

    Cheers & hth.,

提交回复
热议问题