is there native c++ code (i. e. no includes)?

hi guys.

I have some experience in a scripting language called autohotkey, and in there you type and everything works.

for example:

 
msgbox, Testing with a small message


would do what you expect, it brings up a message box with that text and an 'Ok' button.

In c++ I would have to include window.h in order to access the MessageBox() function.

What i have noticed in languages like c++ / java and so on is that often you have to include libraries for things to work, (e.g. iostream for cout).

But that creates the question, are there native c++ functions / objects / commands available for me even when i dont include any standard library?

I know you can create variables, use things like if/else, loops, but are there any functions like for printing on the screen (console programs) and working with strings that do not need being included?

I ask that silly question because including libraries brings the problem that you have to know where the functions you need are located, even though it helps making your program smaller since if you dont need to work with x set of functions then you just dont include that file.
Last edited on
not sure if you are aware, but <iostream> is not for cout. std is. Such as using std::cout so you do not have to say std::cout << .... As far as your direct question I am not sure. I would imagine there are something close to what your are referring to, but the C++ libraries that are built in is not working for you? just curious.
Without libraries, you can in-line assembly code, calling system interrupts. However, this is very hard, system specific, and easy to mess up. Including the libraries is necessary, and this is a good thing, because you can include only the libraries you use, and save space.
encoded wrote:
not sure if you are aware, but <iostream> is not for cout. std is.

If you do not do #include <iostream>
then std::cout << text wouldnt work because cout is an object found in the iostream library, under the namespace "std".

And that is my 'problem' with libraries, you would have to know (probably with time i will get used to it) where the functions you want are located.

The libraries are working just fine. The issue is the following:

1
2
3
4
5
//autohotkey code
var := "one|two|three"

loop, parse, var, |
msgbox, % a_loopfield


would do exactly what you read... it would parse a variable by a specified character (pipe in this case) and then bring a message box with the current parsed string (one, two, three on each case).

When i want to do something similar on C++ I would have to know in which header is the function that might help with this type of action, and for me as a beginner, I find it pretty hard to find those things because:
1 - i dont know where to look and
2 - i dont know how to look for it (except google, but that might not work some times)

@rocketboy

thanks i think that might answer my question, and yes I am aware of the benefit of using libraries, what i thought is that there are some standard functions included in the language itself for ease of use instead of ALL of the language being located in libraries.
Native C++ code is "limited" to all the functionality one would normally have: Classes, Structures, Arithmetical Operations, Built-in Types, etc. etc. Looking closer at this, we find that you practically "inline" an entire library to get around the point of including it.
You can also inline asm, as rocketboy already mentioned. There is however, no real point in doing this; since you will, in any case, make things harder for yourself.
There are IDEs that will write the headers for you.
You could also include all the standard headers (if you do not use a function the compiled code won't be bigger).
You could use the reference in this page, that tells you where is the function located.
thanks for the replies.

So basically i can include the standard libraries but only the functions used will be included?
doesnt that happen with all libraries? if not, why?

as i understand it if i say: #include "libx.dll"
the whole library will be added to my code, potentially making my whole code bigger, while:
#include "stdio.h"
would only include those functions I use from that particular library... is that correct?
You can't include DLLs that way - you have to link your project to a library that references a DLL.
Well... #include is a copy-and-paste function, if you will. This takes place before the compilation of your file starts, so trying to copy and paste dlls into your C++ code could lead to some BIG problems, as dlls aren't C++ files. :)

stdio.h is a header file, meaning it contains all the function and variable declarations for a specific part of a library, but not a thing that translates directly to binary code (there's a good reason for this). These shut the compiler up while it's compiling and stop it complaining about undefined symbols, until the stage where one "links" compiled files and the actual data from the libraries. As far as I know, there is no way to include only certain snippets of a file aside from cutting and pasting.

Most C++ libraries come with header files, although they go under different suffixes (.hpp, .hxx, and rarely no suffix at all).

Does this help?

-Albatross
Topic archived. No new replies allowed.