在同一cout语句中先前赋值后,变量仍未初始化

时间:2016-06-18 02:15:01

标签: c++ visual-studio initialization variable-assignment cout

我是编程新手,并且正在使用Visual Studio 2015上的表达式进行练习。我首先构建了这个程序:

<< "The expression x > 3 has the value " << (x > 3) << ".\n";

编译器发出错误警告:未初始化的局部变量&#39; x&#39;在第11行中使用。它是 ... std::cout << "The expression x = 100 has the value " << (x = 100) << ".\n"; std::cout << "Now x has the value " << x << ".\n" << "The expression x < 3 has the value " << (x < 3) << ".\n" << "The expression x > 3 has the value " << (x > 3) << ".\n"; ... 行。我把程序改为:

EXPLAIN

警告消失了。我的问题是,在第一个程序中,为什么在我分配100之后x仍然未初始化?为什么第11行中的错误而不是第9行或第10行?有没有办法解决问题而不拆分cout语句?

0 个答案:

没有答案