- first code
#include <studio.h>
int main() {
std::cout << "apple" << endl << "banana";
}
- second code
#include <iostream>
using namespace std;
int main(void) {
cout << "apple" << endl;
cout << "banana" << endl;
}
Why am i wrong? i know the answer is second one, But i want to know the why my first code is wrong. Please help me!
take a look at the doc: https://en.cppreference.com/w/cpp/io/manip/endl
as you can see, 2 important things are related to the error/question you posted:
endl
is defined in header<ostream>
std
so it must be used as
std::endl
note that the ostream is a parent of the iostream so including the iostream guaranties you have access to the ostream