检查文件中的每个字符串是否只有一个单词

Check if each string in file have only one word

Input: [1-st string]Dog

[2-nd string]I love dog

[3-rd string]Dog love me

[4-th string]Love

Output: [1-st string]Dog

[2-nd string]Love

How can i do such thing in c++ ?>Without using vector.Thx:)

您有一个格式为 "No A is within a class B" 的问题。此类问题的算法是

bool wrong = false;
while ( /* there is another A */ )
{
   if ( /* check if it is NOT within a class */ )
   {
      wrong=true;
      break;
   }
}
if (wrong)
{
  // here you know that at least one thing was NOT within a class B
}
else
{
  // here you know that every item A was within a class B
}

在你的情况下 "class" 是 "Strings with no space" 并且要检查是否有 space 你只需使用 this condition.