Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

std::ifstream file_1(argv[1]);
std::ifstream file_2(argv[2]);
...
std::string dummy_1;
std::string dummy_2;
...
while(std::getline(file_1, dummy_1) || std::getline(file_2, dummy_2)) // the problem
{
  ...
}

The condition behaves like the OR operator is evaluating the option on the right only if the file on the left reach the end (returning a FALSE) and it doesn't evaluate them at the same time.

I know that the evaluation of a statement has nothing to do with the operator itself or with its own precedence rules, but my program it's not supposed to work like I'm imaging with both statements being evaluated at the same time ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
217 views
Welcome To Ask or Share your Answers For Others

1 Answer

The OR operator is a short circuit operator, meaning that if one side evaluates to true the other side is never actually executed. If your intention is to have both sides of the OR evaluated then you might want to reconsider how your code is written.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...