C++ Output Basics Question!

Asked 2 years ago, Updated 2 years ago, 18 views

I'm a student who just started studying through C++ Jeongol!!

The question is, there are printf and cout in C++, right?

When opening here, printf inserts \n in the middle of the character to open it

In cout, we use the endl to open itYo

My question is whether it is possible to print it out with printf and publish it through endl!!

I don't think it'll work because Cout treats \n as a text, but I want to know if it can be used as an inverse!

c++

2022-09-20 16:22

1 Answers

#include <iostream>
#include <stdio.h>
#define endl '\n'
using namespace std;

int main(){
    char a = 'a';
    cout << "cout: " << a << "\n";
    printf("printf: %c %c",a,endl);
    printf("a");
    return 0;
}
/*
Result
cout: a
printf: a
a
*/

"\n" is also available for both cout and printf. If you want to use endl in printf, you can redefine it like #define endl '\n' and write it like above. (If you just write in "", endl will be printed as it is.)


2022-09-20 16:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.