I am solving the problem of changing the char* array to int.
I knew that atoi() was included in cstdlib, and
When I used the atoi in the professor's ppt, cstdlib was always included,
During this assignment, I observed that it ran well without errors even though I included only iostream without cstdlib.
Below is the corresponding code. I'm so curious why there's no error.
I'm enclosing other header files inside the iostream header file, but those other header files are enclosing another header file again. In the process, there was no error because one header file was enclosing cstdlib.
If I compile the code below, there will be an error. Uncommenting and compiling iostream should not cause errors.
//#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
printf("%d,", atoi("1234"));
}
In the long run, the internal implementation of header files may change, and the embedded header files may change, so when you use a particular function, you must accurately include the header files that contain that function.
© 2024 OneMinuteCode. All rights reserved.