title: C++ store number in char using int variable
body: <p>I need to be able to store number in char using variable and later able to detect if it is number or character for print, will try to explain with below's code sample:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main() {
      vector&lt;char&gt; vChar;
      int testInt = 67;
      char testChar = 'x';
      char printChar;
  
      vChar.push_back(testInt);
      vChar.push_back(testChar);
  
      while (!vChar.empty()) {
          printChar = vChar.back();
          vChar.pop_back();
          cout &lt;&lt; printChar &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Above code will output "x C", which is incorrect, because "cout" is printing "printChar" as char not as int and 67 is C in ASCII.</p>
  
  <p>I could cast "int" over "printChar" but that would make it output "120 67", which is still incorrect. I have also tried to use conditions to detect which one is number, which one is character.</p>
  
  <pre><code>while (!vChar.empty()) {
      printChar = vChar.back();
      vChar.pop_back();
      if (isdigit(printChar)) {
          cout &lt;&lt; int(printChar) &lt;&lt; endl;
      }
      else {
          cout &lt;&lt; printChar &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>but "isdigit()" is never triggered and the result is same as without "int" cast...</p>
  
  <p>How can I correctly print/output string for both numbers and characters using "char" type?</p>
  
  <p>PS. I'm doing this for my school project to calculate matrixes, and using char for symbolicmatrixes is forced, thus I have to somehow be able to store both character and integer using char while differentiating them from each other.</p>