Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6774621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:48:34+00:00 2026-05-26T15:48:34+00:00

This does not work. I’m trying to learn how to use std::copy but I

  • 0

This does not work. I’m trying to learn how to use std::copy but I can’t find any working code.
I ran this in gcc 4.6.1. And it does not do anything when I hit control D. If I hit Control C…it prints out the new lines only.

Found code here:

Printing an array in C++?

#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <iterator> 

int main() 
{ 
    std::vector<int>    userInput; 

    // Read until end of input. 
    // Hit control D   
    std::copy(std::istream_iterator<int>(std::cin), 
              std::istream_iterator<int>(), 
              std::back_inserter(userInput) 
             ); 

    // Print in Normal order 
    std::copy(userInput.begin(), 
              userInput.end(), 
              std::ostream_iterator<int>(std::cout,",") 
             ); 
    std::cout << "\n"; 

    // Print in reverse order: 
    std::copy(userInput.rbegin(), 
              userInput.rend(), 
              std::ostream_iterator<int>(std::cout,",") 
             ); 
    std::cout << "\n"; 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:48:34+00:00Added an answer on May 26, 2026 at 3:48 pm

    Not sure how you’re running it or what you’re entering but that seems to run fine for me:

    pax$ g++ -o qq qq.cpp ; ./qq
    1
    2
    3
    4
    5
    0
    9
    8
    7
    6
    <CTRL-D>
    1,2,3,4,5,0,9,8,7,6,
    6,7,8,9,0,5,4,3,2,1,
    

    This is with gcc 4.3.4 under Cygwin. One thing to watch out for is that (in my environment at least), CTRL-D has to be entered on a new line. Entering:

    1 2 3 4 5<CTRL-D>
    

    didn’t work for me (the CTRL-D was ignored) but:

    1 2 3 4 5
    <CTRL-D>
    

    did.

    You can bypass those issues with CTRL-D by doing something like:

    echo 1 2 3 4 5 6 7 8 9 0 | ./qq
    

    so that end of file does not depend on your terminal characteristics. This is especially important since it may be that MinGW (being a Windows application rather than running under CygWin’s emulation layer) requires the Windows end-of-file character, CTRL-Z.

    Running this command acts as expected:

    pax$ echo 1 2 3 4 5 6 7 8 9 0 | ./qq
    1,2,3,4,5,6,7,8,9,0,
    0,9,8,7,6,5,4,3,2,1,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying something like this, but this example does not work. jsObj = {};
These urls work: /admin /admin/appname But this does not work for any model, including
I'm trying to understand why this does not work. (Basic example with no validation
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,
I'm newbie in Python. I can't understand why this code does not work: reOptions
This does not work, should it? Or can you stop the error if another
Can anyone tell me why this does not work? I would have thought the
A small problem. Any idea guys why this does not work? int? nullableIntVal =
Is there any way how to do that? This does not work: SqlCommand command
This is really basic PHP. Can someone tell me why this does not work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.