C++ 非常奇怪的挂起在for循环初始化
我有一个很奇怪的错误,我似乎无法理解。我已经把它缩小到了代码的一小部分(除非编译器对我的语句重新排序,我不相信这是真的)C++ 非常奇怪的挂起在for循环初始化,c++,vector,for-loop,iterator,C++,Vector,For Loop,Iterator,我有一个很奇怪的错误,我似乎无法理解。我已经把它缩小到了代码的一小部分(除非编译器对我的语句重新排序,我不相信这是真的) 。。。 std::cout您应该尝试的第一件事是在每个字符串之后输出std::endl。这将刷新输出的缓冲区。您应该尝试的第一件事是在每个字符串之后输出std::endl。这将刷新输出的缓冲区。以下程序(其中有一些您没有的额外换行): 这似乎是您所期望的,因此我不确定您这方面的问题出在哪里,但可能是在跳过的代码中。以下程序(其中有一些您没有的额外换行): 这似乎是您所期望的,
。。。
std::cout您应该尝试的第一件事是在每个字符串之后输出std::endl
。这将刷新输出的缓冲区。您应该尝试的第一件事是在每个字符串之后输出std::endl
。这将刷新输出的缓冲区。以下程序(其中有一些您没有的额外换行):
这似乎是您所期望的,因此我不确定您这方面的问题出在哪里,但可能是在跳过的代码中。以下程序(其中有一些您没有的额外换行):
这似乎是您所期望的,因此我不确定您这方面的问题出在哪里,但可能是在跳过的代码中。我运行了您的代码,并且它按预期运行(我得到的输出不是在这里,或者是在heredo我得到了n循环?或者在这里)。这可能是您在循环内或代码顶部的..
中正在做的事情。我猜是..
在做这件事。它可能无法正常工作,但您看不到它,因为它进入了某个无限循环,而没有刷新输出。-出于这个原因,请使用cerr
进行调试输出。我运行了您的代码,它按预期运行(我得到的输出不在此处或herdo,我得到的是n循环?或此处
)。这可能是您在循环内或代码顶部的..
中正在做的事情。我猜是..
在做这件事。它可能无法正常工作,但您看不到它,因为它进入了某个无限循环,而没有刷新输出。-因此,使用cerr
进行调试输出。
...
std::cout << "here"<< std::endl;
std::vector<int>::iterator n_iter;
std::vector<int>::iterator l_iter;
std::cout << "here?" << std::endl;
for(n_iter = n.begin(), std::cout << "not here" ; std::cout << "or here" && n_iter < n.end(); n_iter++)
{
std::cout << "do i get to the n loop?";
...
}
#include <string>
#include <iostream>
#include <vector>
int main() {
std::vector<int> n;
n.push_back(3);
n.push_back(3);
n.push_back(3);
std::cout << "here"<< std::endl;
std::vector<int>::iterator n_iter;
std::vector<int>::iterator l_iter;
std::cout << "here?" << std::endl;
for(n_iter = n.begin(), std::cout << "not here\n" ; std::cout << "or here\n" && n_iter < n.end(); n_iter++)
{
std::cout << "do i get to the n loop?\n";
}
}
[5:02pm][wlynch@orange /tmp] make foo
g++ foo.cc -o foo
[5:02pm][wlynch@orange /tmp] ./foo
here
here?
not here
or here
do i get to the n loop?
or here
do i get to the n loop?
or here
do i get to the n loop?
or here