You must study stream
of io and their handlers. Example:
#include <iostream>
using namespace std;
int main() {
auto x = 65;
cout << "i make " << x << " program\n";
cout << "i make " << hex << x << " program " << endl;
cout << "i make " << (char)x << " program " << endl;
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
The printf()
works with conventions where it replaces a part of the text with something that comes as a parameter, and what’s used there as placeholder determines what to do. C++ uses data flows that line up and produce a result. So he assembles each element and the first item is who receives everything that comes after. The cout
is the output to the console.
Obviously knowing the value it’s best to put it all together in one string only. It’s only legal to use this when you don’t know what you’ll get in the placeholder, then in this case we will understand that this x
would be a value that comes externally.
The second example sends to a handler before sending to the exit and the hex
changes the number output format to hexadecimal, such as %x
would.
I also used \n
and endl
, even though both end a line has differences between them (see link above).
The third example had to convert from number to char
at hand. Good C compilers configured appropriately require the same. Note that the stream doesn’t care about the guy who comes. If the guy has a stream configured it will know what to do. All basic language types have, and all types should have some operator stream
configured, it’s like a ToString()
of other languages.
In the posted documentation there are several other very useful modifiers for data formatting. You can even create your own with a little more knowledge.
Got it, you would have a website with a list of variables of this type? , hexadecimal, whole etc...? I need a lot because I have an activity to transform code c in c++.
– Vitor Gonçalves
Hexadecimal is not a type is a representation and is in link I passed, a start of the types is in https://en.cppreference.com/w/c/language/type. This is official "almost" documentation. I suggest studying it from end to end. You’re probably studying for a bad book, or you’re not interpreting the text correctly. There’s a lot of traps out there, mostly free stuff. In fact maybe you are having difficulty for lack of a base of other things of the computation, it may be that you are using something didactic, what is very common, in general the material expects that you already have a good base.
– Maniero
especially in C++ which is one of the hardest languages to learn.
– Maniero
I searched a lot of books that indicate teaching at the beginning , comparing the beginning of the book where I am with youtube videos I find it super similar only changing the fact that the book has exercises , which part you recommend me learn before? a specific topic because really learning c and c++ together is complicated.
– Vitor Gonçalves
C and C++ are very different languages and one of the big problems is that almost everyone teaches as if they were the same, this is already a very basic mistake that shows that the person who is teaching does not know what they are talking about. Very, very common indeed. You have to learn fundamentals, understand how the computer works, what’s behind every aspect of the language, why things are the way they are, terminology, computational concepts. Everybody skips that part and so there’s a lot of zombie programmer out there.
– Maniero
It’s just that I really need to understand both as soon as possible, what’s your recommendation? , focus on c and go slow with c++ or some other?
– Vitor Gonçalves
I don’t know, depending on what you want, I’d go in one, C’s a lot easier. I know very few people who understand both, I wouldn’t waste time trying. There are some very dedicated and experienced guys who can’t be good at both, just seeing the way you write and do things I think will have difficulty with C that is much simpler. Seeing other comments, I think you’re "lotion" and have no idea what you’re getting yourself into.
– Maniero
in life everything is a challenge and nobody is born knowing , I will start by c even I will 'skip' the part of the book that explores c++ and continue in c , thanks for the comments and the links , will serve me a lot!
– Vitor Gonçalves
There’s a challenge and sticking your foot in the jackfruit
– Maniero
thousand rsrs will give up your right , 10 thousand your left , but you will not give up!!! p
– Vitor Gonçalves
@Vitorgonçalves probably the idea of the comments above is not to make you give up, but to make you "not insist wrong". What counts in perseverance is the effort to understand right and wrong and improve and correct what you do. Do not insist on error, because this is a waste of time. From the moment you say, "I really need to understand both of you as quickly as possible," either: Or as Maniero said, you’re "sticking your foot in the jackfruit," or you either emphasize the "quick POSSIBLE" you said yourself, and slow down a little by doing the basic steps, that there will be worth it.
– Bacco
I really exaggerated , is that my college will start now and was a couple of years stationed only working with assembly and maintenance , never learned anything about programming and the course of information technology by grid will be necessary to have a lot of knowledge in this area , I’m studying straight to try to get there and not have too many difficulties.
– Vitor Gonçalves