c to c++ code converter
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Converted C code to C++ code with explanations
#include <iostream>
int main() {
std::cout << "Hello, World!";
return 0;
}
Explanation:
- Replaced
#include <stdio.h>
with#include <iostream>
to use C++ input/output stream. - Replaced
printf("Hello, World!");
withstd::cout << "Hello, World!";
to use C++ output stream for printing. - Removed the
return
type ofmain()
function, as it defaults toint
in C++. - Added
std::
prefix tocout
to specify the namespace for thecout
object. ```