Check if std::wstring is null or empty

subs picture subs · Mar 21, 2011 · Viewed 17.8k times · Source

How to check if an std::wstring is null or empty?

Answer

GManNickG picture GManNickG · Mar 21, 2011

wstring is not a pointer, it cannot be null. You can check if it's empty (that is, is equivalent to "") either by direct comparison to the previous, or by:

str.empty(); // == (str.size() == 0)