Q:

Write a program to read a sequence of strings from the standard input into a deque. Use iterators to write a loop to print the elements in the deque

0

Write a program to read a sequence of strings from the standard input into a deque. Use iterators to write a loop to print the elements in the deque.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <deque>
#include <iostream>
#include <string>

int main() {
  std::deque<std::string> words;
  std::string word;
  while (std::cin >> word)
    words.push_back(word);

  for (std::deque<std::string>::const_iterator it = words.cbegin();
       it != words.cend(); ++it)
    std::cout << *it << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now