title: How do I get character by character input in c++?
body: <p>First I need to read two integers N &amp; Q separated by space. I am doing this using cin. Then in next two lines two binary numbers each of N digits follow. I am trying to read these numbers bit by bit using getchar() and putting them into int vector but it is printing garbage values. Is there a problem with new line character. I know I could first read them into a string and then put them into vector but I wanted to do this way. Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  int main(){
      int N;
      int Q;
      cin &gt;&gt;N&gt;&gt;Q;
      string A, B;
      //cin &gt;&gt; A&gt;&gt;B;
      vector &lt;int&gt; Abit;
      vector &lt;int&gt; Bbit;
  
      for (int i=0;i&lt;N;i++){
          char c= (int) getchar();
          Abit.push_back(c);
      }
      for (int i=0;i&lt;N;i++){
      //  cout &lt;&lt; Abit.at(i);
          char c= (int) getchar();
          Bbit.push_back(c);
      }
      for (int i=0;i&lt;N;i++){
          cout &lt;&lt; Abit.at(i);
      //  char c= (int) getchar();
      //  Bbit.push_back(c);
      }
  }
  </code></pre>