Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 非常奇怪的挂起在for循环初始化_C++_Vector_For Loop_Iterator - Fatal编程技术网

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