Using atoi() and stderr to convert string to integer

  atoi, c++, integer, stderr, string

I’m trying to use atoi() to convert a string to an integer, print the integer, and use stderr to give an error message. I’m not sure how to use stderr.

#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
  char* str;
  int result;
  
  cout << "Please enter a number to convert to a string." << endl;
  
  cin >> str;
  result = atoi(str);


  fprintf (stdout, result);
  fprintf (stderr, result);

}```

Source: Windows Questions C++

LEAVE A COMMENT