0

This is the code just trying to output the first number of a sequence.

but when i input1 1,finish with crtl+d the output is 1D .When I input-1 -1finish with crtl+d the output is-1without a wierd 'D'.

Why will that D shows up. I think the code is right and it maybe some update in terminal or g++ that cause the problem. Is anyone has some other ideas?

P.S. I use g++ to compile and it works good on teacher's unix platform. The code is following:

#include <iostream>
#include <cstdlib>
#include <vector>
std::vector <int> N;
int main(int argc, const char * argv[]) {
   int tok;
   while (std::cin >> tok){N.push_back(tok);}
   std::cout << N[0]<<std::endl;
   return 0;
}
Lewis
  • 70
  • 8
Donut
  • 1
  • 1
    I'm pretty sure you're seeing the "D" from hitting "^D" (and then overwriting the "^". `echo "1 1" | ./a.out` doesn't produce that output. – Wooble Oct 16 '14 at 15:40
  • possible duplicate of [CTRL-D on Mac terminal outputs a D character](http://stackoverflow.com/questions/25756825/ctrl-d-on-mac-terminal-outputs-a-d-character) – Elliott Frisch Oct 16 '14 at 16:50
  • @Wooble, thank you very much. it works. But can I just input and get the output without D? Because in Unix , i don't have that problem. – Donut Oct 16 '14 at 17:08
  • @ElliottFrisch, Yes, I have seen this question.The method provided is successful in C. But I am not an expert. I don't know how to do this in c++. – Donut Oct 16 '14 at 17:10
  • 1
    Well, `sleep()` isn't really a solution to the problem, IMO. Normal unix tools that read from stdin and write to stdout don't seem to do this on OS X, and they don't rely on sleeping. – Wooble Oct 16 '14 at 17:14

0 Answers0