Q:

Printing all Blanks (literally no tokens are printed)

Basically my code doesn't print the tokens. It just prints blanks. What am I doing wrong?
I've consulted many other guides on this issue and I can't seem to understand what I'm doing wrong.
Thanks.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stack>
#include <stdexcept>
#include <string>
#include <stdlib.h>
#include <cstring>
using namespace std;

int main() {
  stack<double> s;
  string str = "";
  getline(cin, str);
  char *cstr = new char [str.length()+1];
  strcpy(cstr, str.c_str());
  char* strp = strtok(cstr, " ");
  while (strp != 0){
        double n = strtod(cstr, &strp);
        s.push(n);
        cout << strp << endl;
        strp = strtok(0," "); 
        }
  return 0; 
}

A:

This code works for me:
int main()
{
   stack<double> s;
   string str = "";
   getline(cin, str);
   char *cstr = new char [str.length()+1];
   strcpy(cstr, str.c_str());
   char* strp = strtok(cstr, " ");
   while (strp != NULL)
   {
      double n = strtod(strp, NULL);
      s.push(n);
      cout << n << endl;
      strp = strtok(NULL, " "); 
   }

   return 0;
}

But hell, this really is a painfull mix of C and C++. You should get rid of those strcpy, strtok and strod functions. Use istringstream instead. 

