I tried to read lines from file, push every 5 lines into one deque dq, then push dq into a deque ques. The dq successively got 5 lines, but after push_back the dq into ques, the debuger shows that one empty queue was inserted into ques, shown below is the output from debugger.
ques std::__1::deque<std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::allocator<std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > size=1
[0] std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > size=5
[0]
[1]
[2]
[3]
[4]
dq std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > size=5
[0]=std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > "CCCGGGT"
[1] std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > "CCCCGCA"
[2] std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > "GGGCCTC"
[3] std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > "GGGGGGC"
[4] std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > "TTTGCCT"
Any idea what's wrong?
deque<deque<string>>ques;
deque<string> dq;
while (std::getline(inputstream, line))
{
if(linecount<5)
{
dq.push_back(line);
linecount++;
}
else if (linecount == 5)
{
deque<string> dq2;
dq2 = dq;
ques.push_back(dq2);
linecount=0;
dq.clear();
}
}
Finally find the code works what I expected. The debug shows the ques' content empty. But actually, there are element in it. I can count it's content. Don't know why debugger doesn't show the content of a deque inside a deque.