Header Files - C++ Tutorial For Beginners #14

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии • 150

  • @scottblake89
    @scottblake89 2 года назад +10

    I love that you jump right into it... it seems like all the most viewed or liked videos start off with trying to sell something and i cant stand that..

  • @alex_mahone
    @alex_mahone 4 года назад +47

    Love your teaching style! I always learn something new when you post a new video!

    • @NeuralNine
      @NeuralNine  4 года назад +2

      appreciate it :)

    • @christreedee
      @christreedee 3 года назад +1

      @@NeuralNine how does one run one of these .h files thanks :)

  • @Guy-bf7wm
    @Guy-bf7wm 4 года назад +18

    Really thank you for these tutorials, I'm starting with competitive programming and I wanted to use c++ and suddenly I saw these videos and they really helped me.

  • @bachirdekdouk5440
    @bachirdekdouk5440 9 месяцев назад +3

    How do you configure this include in the tasks.json file if you dont want to do it from command line ?

  • @tamirrozenfeld3572
    @tamirrozenfeld3572 2 года назад

    Finally i found a video that explain what header is and not make me watch 30 minutes video hoping to hear or get a hint of what header is !
    THANK YOU VERY MUCH!

  • @wangxian7924
    @wangxian7924 3 года назад +8

    This video was very clear and amazingly explained. Learnt a lot! Thank you.

  • @m7md_alj
    @m7md_alj 2 года назад

    you have no idea how long i spent trying to figure out how to use the header file tysm

  • @rouisaek
    @rouisaek Год назад

    The header feels like an Interface. Nice tutorial

  • @fatman2217
    @fatman2217 3 года назад

    I wasted 3 days looking for a fix on how to include user-made header files, it always caused a linker error in VS Code, can't thank you enough for this video mate :)

  • @JianqiuChen
    @JianqiuChen 2 года назад +2

    still does not work, it says main.exe is not recognized! vscode and c++ is the hardest config that I have done in my life, 4 hours watching videos cannot get a damn hello world + another class set up. And are you telling me that I have to run the command "g++ -o main.exe main.cpp includes/mynewclass.cpp" every time I create a new class???

    • @Matdrox
      @Matdrox 2 года назад +2

      I'm wondering this too...

  • @JoaoPedro-nh7uw
    @JoaoPedro-nh7uw Год назад

    Thank u so much. I was having problem with a function that was being undefined, and you just saved me😃

  • @33samogo
    @33samogo 3 года назад +2

    how did you compilie with g++ -o main.exe main.cpp includes/calculations.cpp commanad?! is not working for me, it works with g++ main.cpp includes/calculations.cpp -o main.exe. What I am missing here? Is there a way to configure Compile Run "F6" command to work with includes?

  • @zCesarZ
    @zCesarZ 21 день назад

    Thank you, very well explained!

  • @krakusek865
    @krakusek865 3 года назад +4

    here I found what I was looking for, a very good video. Thank you bro!

  • @ebiscaia
    @ebiscaia 3 года назад +8

    Hi, is there a way to edit the task.json to include something like "include/*.cpp" to compile everything with F5?

    • @Aikocake
      @Aikocake 2 года назад

      Any update to this inquire?

    • @ebiscaia
      @ebiscaia 2 года назад

      @@Aikocake Unfortunately not

    • @RosinenbomberPilot
      @RosinenbomberPilot Год назад

      @@ebiscaia Have you found a solution yet?

    • @ebiscaia
      @ebiscaia Год назад

      @@RosinenbomberPilot nope, mate. It’s been a while I don’t use C++

    • @DadicekCz
      @DadicekCz Год назад

      ​@@ebiscaiabruh, one would say it is one of the most basic things a programmer can do. I'll never stop hating this system

  • @ricardocarvalhomiguel2684
    @ricardocarvalhomiguel2684 3 года назад

    Thank you very much for the video, I'm from Brazil and only used C ++ in VS2019, and this video helped me to understand how to compile headers files. I will follow more videos from your Channel

  • @janmichaelaustria620
    @janmichaelaustria620 3 года назад +3

    Nice video man! I spent hours trying to find a work around for CMake, and this cleared it up in like 5 mins! You rock!

  • @agentstona
    @agentstona 2 года назад +2

    but what if you have 5 different headers that you use for 5 different things at compile do you have to also specify the other 5 different .cpp files ?

    • @deadeye8
      @deadeye8 2 года назад

      Thats where
      #pragma once
      Comes into play

  • @sashokostadinov5773
    @sashokostadinov5773 3 года назад +4

    Thank you so much! I am also using the extension and yesterday we started learning about header files and I was wondering what was I doing wrong. I found from internet which file what should it contain but I could not find why it was not compiling.

  • @danieladeba206
    @danieladeba206 9 месяцев назад

    Wow,Thank you you made me to come out confusion of running c++ with the header files.

  • @enigma3292
    @enigma3292 4 года назад +4

    Great vid!

  • @slattsan1315
    @slattsan1315 2 года назад

    Great tutorials bro, refreshed my c++ quick and good w this series

  • @clarkniyonzima9724
    @clarkniyonzima9724 Год назад +3

    I have a question, what about the #ifndef, #define and #endif in the header file

    • @ahmedosama6856
      @ahmedosama6856 11 месяцев назад

      Its a best practice for files validation

  •  2 года назад

    So, linker identify the implementation of the declaration just by the same filename? What about include guard i learned in C. its not relevant anymore?

  • @cenkerozkan9906
    @cenkerozkan9906 Год назад

    You explained it very simply and clearly. It couldn't have been explained better. Thanks

  • @sinapiranix
    @sinapiranix 2 года назад

    thank you man! youre best teacher for c++

  • @ayushdubey8745
    @ayushdubey8745 2 года назад +1

    How to run a project with a single header file and multiple source files?

  • @DeepakPandey-dn9iz
    @DeepakPandey-dn9iz 5 месяцев назад +1

    thank you so much sir. I was facing issues with linking the files.

  • @jersondereal
    @jersondereal 2 года назад +1

    Help🥲 The command isnt working, i keep getting this error, cc1plus.exe: fatal error: main.cpp: No such file or directory
    compilation terminated.

    • @AyaGamal2010
      @AyaGamal2010 Год назад

      for this problem in VS code : The term 'g++' is not recognized as the name of a cmdlet, function,....
      solution : ruclips.net/video/5hSRaW4swto/видео.htmlsi=zzxcLPnKLhjL0cP3

  • @ali_youtube_user_7351
    @ali_youtube_user_7351 6 месяцев назад

    How can I make a header file with its imolementation file that can be included and used across any cpp filed without explicitly including it to your project ? Just like C++ header files (iostream, vector, etc)

  • @malolan98
    @malolan98 4 года назад +1

    Keep going! Really great method of teaching!

  • @sinaghezeljeh2227
    @sinaghezeljeh2227 4 года назад +3

    great video again like every time

  • @TheUruz
    @TheUruz Год назад

    what if you end up having to compile two files with two implementations of, say, the add function?

  • @livedreamsg
    @livedreamsg 4 года назад +2

    So is there any way to get Visual Studio Code to do this for me? I have to jump to the terminal every time, as Visual Studio doesn't recognize it at all. At that point I'm much better off just using Vim.

    • @NeuralNine
      @NeuralNine  4 года назад

      It's always better to use vim

  • @mrbout8911
    @mrbout8911 4 года назад +2

    In the next videos, you can enlarge the font a little to be clear because I am using the phone and thank you for the effort

  • @robromijnders
    @robromijnders 2 года назад

    This is really great, thanks for posting!

  • @hallucinatory.767
    @hallucinatory.767 2 года назад

    Thanks for the tutorial bruh! That's Amazing.

  • @ViktorKatzy
    @ViktorKatzy 10 месяцев назад +1

    The only reason why his C++ code works is that it's afraid of his biceps an getting punched 😹😼 but jokes aside, very good explanation, really helped me out!

  • @danielschaad3084
    @danielschaad3084 2 года назад +1

    what would be the command line in the case I have multiple header files? Do I have to write every single one? or is there a way to compile the whole folder "includes"?

    • @leonwozniak9456
      @leonwozniak9456 Год назад +1

      i have a same problem, did u find any solution?

  • @evrolcuk2046
    @evrolcuk2046 5 месяцев назад

    does "not adding the .cpp file" directly have any importance in terms of privacy? i didn't get that?

  • @danykmk1174
    @danykmk1174 4 года назад +1

    believe me !!! You are the best for me !!!!! your method is great

  • @syldris
    @syldris 3 года назад +1

    Is there any way to run (or execute) the main code(main.cpp) without typing a command such as "g++ -o main.exe main.cpp calculations.cpp"?
    In Visual Studio (not VS Code), it allows to users to have a class with its header file(.h) and definition file(.cpp) and run it without any single special terminal command,
    as long as all the files are in the project folder.
    It seems like VS Code does cannot find the header file's directory on its own.

    • @luke7049
      @luke7049 3 года назад +2

      The 'button' you press in Visual Studio is basically an automated implementation of compiling the source code (i.e using the terminal command)

    • @hodayfa000h
      @hodayfa000h Год назад

      BRO
      just use visual studio
      it is 100 times better

    • @hodayfa000h
      @hodayfa000h Год назад

      of course as an ide Not a code editior

    • @syldris
      @syldris Год назад +1

      @@hodayfa000h Agreed! Already swapped to VS!

    • @hodayfa000h
      @hodayfa000h Год назад

      @@syldris oh yeah this was 1 year ago of course it changed

  • @hyperbhavik
    @hyperbhavik 2 года назад

    Finally got it, thank you very much

  • @Jonathan-ru9zl
    @Jonathan-ru9zl 2 года назад

    Hi! How come i have .cpp file that uses stdio.h library and uses printf function?

  • @yumyumtales
    @yumyumtales 3 года назад +1

    Great video !!! very well explained

  • @tamimkhan7919
    @tamimkhan7919 2 года назад

    Thanks teacher this video was really helpful for me.

  • @rodrigotorres6426
    @rodrigotorres6426 3 года назад

    Nice video, months to searching this!!

  • @ZAblaze
    @ZAblaze 2 месяца назад

    thank you in 2nd class of programming and they taught this in the first one but i didn't pay attention in that lesson lmao

  • @AbhishekYadav-ni5ts
    @AbhishekYadav-ni5ts 3 года назад

    Thank u very much...... This video helped me alot... Thank u 🙏🙏

  • @Galaktium
    @Galaktium 3 года назад

    Nice vid, very clear, very helpful.

  • @vukkulvar9769
    @vukkulvar9769 Год назад

    Why can't gcc implicitely fetch all the needed files?
    Why can't you declare what's made visible outside the .cpp file without using a .h file, but by using a "export" keyword for example?

    • @AyaGamal2010
      @AyaGamal2010 Год назад

      for this problem in VS code : The term 'g++' is not recognized as the name of a cmdlet, function,....
      solution : ruclips.net/video/5hSRaW4swto/видео.htmlsi=zzxcLPnKLhjL0cP3

  • @larissasouza8169
    @larissasouza8169 3 года назад

    Great video, thank you so much for that!

  • @ric7702
    @ric7702 3 года назад +1

    A bad practice but it really works, actually that is the only one that worked for me, I could't made work the one with the header file. I am working with C in VSC. But well at least one way worrked for me. Greetings.

  • @killzann7757
    @killzann7757 4 года назад +1

    love it bro

  • @juanjocg1870
    @juanjocg1870 4 года назад +4

    love it

  • @doc9448
    @doc9448 3 года назад +2

    Thanks for your instruction! Very easy to understand and informative!

  • @naheliegend5222
    @naheliegend5222 2 года назад

    But what if I have 100 of those header files and cpp files? Should I add all of them to the g++ command?

  • @Rita-og7cy
    @Rita-og7cy 3 года назад

    wait you might have just saved my life

    • @Rita-og7cy
      @Rita-og7cy 3 года назад

      nope still not working

  • @byrussx
    @byrussx 4 года назад +2

    great video

  • @aashishpanchal3022
    @aashishpanchal3022 3 года назад

    Thankyou so much sir, really help full.

  • @Steezylegs_juri
    @Steezylegs_juri Год назад

    really well done thanks

  • @AyaGamal2010
    @AyaGamal2010 Год назад +1

    for this problem in VS code : The term 'g++' is not recognized as the name of a cmdlet, function,....
    solution : ruclips.net/video/5hSRaW4swto/видео.htmlsi=zzxcLPnKLhjL0cP3

  • @antmoundsock1122
    @antmoundsock1122 3 года назад

    i get 3 errors depending on my variables: 'x': identifier not found, 'y' undeclared identifier, and 'z': redefinition, multiple initialization

  • @casperongny802
    @casperongny802 3 года назад

    Hey, what is your intro? BGM

  • @dakshdesai
    @dakshdesai 4 года назад +3

    Sir can you make a obs studio with python

  • @shahidashadan4104
    @shahidashadan4104 3 года назад

    I'm currently using arduino IDE software,but when I'm trying to upload the coding,there are some error and it show a message 'no header files (.h) '
    What should i do?
    Anyone help me please?
    I really need your help.

    • @shahidashadan4104
      @shahidashadan4104 3 года назад

      And if i not notice someone reply my comment,kindly dm me at instagram. Tq in advance
      Ig : nrlsy_hda

  • @BunrithViwatthanak
    @BunrithViwatthanak 3 месяца назад

    What is the keyboard?

  • @123userthatsme
    @123userthatsme Год назад

    Thank you for explaining the h vs cpp thing, i.e. being able to hide the actual functions in cpp. I didn't understand why the boilerplate was duplicated... it was driving me nuts!

    • @rouisaek
      @rouisaek Год назад +1

      the .h file is like a contract to the end user. and they are not duplicated cuz the .h file have the declaration methods and the .cpp file must have the definition of that methods.

    • @AyaGamal2010
      @AyaGamal2010 Год назад +1

      @@rouisaek Good clarification!

    • @rouisaek
      @rouisaek Год назад +1

      Thanks

  • @homelikebrick42
    @homelikebrick42 4 года назад +16

    Why should the files have to have the same name?

    • @Inoom.
      @Inoom. 6 месяцев назад +1

      They don't have to.

    • @imfurrytrash6769
      @imfurrytrash6769 Месяц назад

      For the most part I believe it never really matters how you name stuff you just need to be consistent with it. My intro to c++ professor will have the header file's class as the title. You just need to make sure that you type it out exactly the way you named the file when you go to include it in the source file

  • @lucasjoss5733
    @lucasjoss5733 3 года назад

    tanks bro, you realy help me to
    solve the compiler error

  • @joaquins.a.2830
    @joaquins.a.2830 4 года назад +4

    In my case it only worked with include "calculations.cpp" or include "calculations.h". with include "includes/calculations.cpp or .h" i got an error.

    • @ASHISHKUMAR-gh1uu
      @ASHISHKUMAR-gh1uu 3 года назад +3

      After creation of main.exe
      Include your header file in calculation.cpp file i.e #include"calculation.h"
      And then in main.cpp makes changes of #include "Includes/calculation.h"
      After that in new terminal
      Write
      g++ -o main.exe main.cpp Includes/calculation.cpp
      Hit enter
      And then write
      main.exe
      It will give result

    • @dankcherries22
      @dankcherries22 3 года назад +1

      @@ASHISHKUMAR-gh1uu He has his calculations.h file in a folder called includes, so "includes/calculations.h" is the path to the calculations.h file. If your calculations.h file is in the same folder as your main.cpp file you only need to have #include "calculations.h"

  • @skaterfabi11
    @skaterfabi11 4 года назад +1

    Thx 4 your videos :)

  • @Jim-tv2tk
    @Jim-tv2tk 4 дня назад

    I am confused. I thought that a header file is MyFile.h and a c++ file is MyFile.cpp. Looks like you are just creating another c++ file and doing an include. How it that a header file? And isn't c++ OOP? Why no classes? PS. I am a C# :)

  • @Robin-gd8py
    @Robin-gd8py 2 года назад

    Thank you so much.

  • @catorlife
    @catorlife Год назад +1

    for some computers, you can't run the "main.exe" command in the terminal, you need to rewrite it as ".\main"

  • @thechosenone7465
    @thechosenone7465 Год назад

    thanks you❤

  • @Sakapaka
    @Sakapaka Год назад

    i didnt understand how the calculations.h had access to the calculations.cpp because u didnt inclue the cpp file in the header file

    • @rouisaek
      @rouisaek Год назад

      It happens under the hood cuz of the naming conventions. all you need to know is your xxxx.cpp file that have the implementation of the logic must have a xxxx.h file with the exact name that acts like an interface for the users. Now inject the xxxx.h not the xxxx.cpp that must be private.

  • @randomhuman5539
    @randomhuman5539 2 месяца назад

    You saved me thank you

  • @DepechLyot
    @DepechLyot 3 года назад

    Greetings from russia! and thank you for teaching me!

  • @saadblabla
    @saadblabla 11 месяцев назад

    I still don't get why you would use header files if you can use the cpp instead, you are not hiding your source code using h files the implementation in cpp files shows all the files there.

  • @mrentp
    @mrentp Год назад

    Isn't this working as interfaces ??

  • @HousseinAlDroubi
    @HousseinAlDroubi 4 месяца назад

    Good, welcome to you.

  • @junkdog505
    @junkdog505 3 года назад

    Gracias a tu video encontré la forma de ejecutar los headers no lo encuentro en otros videos se me hace muy pesado el visual studio 2019 ty

  • @DrFerdy
    @DrFerdy 2 года назад

    dude,you are using the different version of microsoft visual studio that i use,probably that "most" people use
    we use the community version

  • @RenderDragon
    @RenderDragon 3 года назад +1

    You should name your channel as Brainpods

  • @badmonkey2468
    @badmonkey2468 Год назад

    very good

  • @lal1th
    @lal1th 3 года назад

    Okay, so I don't usually comment on videos but this annoyed the hell out of me so I am going to comment if someone else has the same issue
    If everything works up till the point where he types main.exe and then it just shows you an error message, make sure you are using command prompt as your terminal, or use the equivalent command in your terminal
    Great video tho! 👍
    (edit: just some punctuation)

  • @uhhuh5934
    @uhhuh5934 Год назад

    Thanks

  • @mengjingyang4596
    @mengjingyang4596 3 года назад

    why the last step is to type main.exe

  • @costantinoanea682
    @costantinoanea682 4 года назад +3

    🤩

  • @beauMax
    @beauMax Год назад

    Classes?

  • @tips1483
    @tips1483 4 года назад +2

    Can you livestream you coding some day :)

    • @NeuralNine
      @NeuralNine  4 года назад +3

      it's on my todo list. sooner or later I will do it :)

    • @tips1483
      @tips1483 4 года назад

      @@NeuralNine Ok thanks!

  • @Devansh__Pandey2409
    @Devansh__Pandey2409 3 года назад

    includes is not working for me

  • @mubarakoyeyinka8520
    @mubarakoyeyinka8520 3 года назад

    Thanks a lot :) your explanation did help me!. I am trying to use both g++ and cl compiler and I just follow your example using "cl /Zi /EHsc /nologo /Fe:main.exe main.cpp Random1.cpp" in powershell from the working directory. And that's work!

  • @alexsonic7
    @alexsonic7 2 года назад

    bro everybody is asking about several includes, i think that can be achieved with a makefile

  • @catorlife
    @catorlife Год назад

    gosh, why it's so difficult, too many perplexed frameworks
    you guys just need to switch to VS (purple one) and then you will see it much much easier, just "pragma once" and then everything is on the set

  • @Hoxolotl
    @Hoxolotl Год назад

    so instead of including calculation.cpp you include calculation.h. And the only use for a header file is to make the code more readable by moving the logic back to a second file. Why does it feel like using a sledgehammer on a mosquito? As if back in the days when C was invented "readability" was on the menu. I bet there is a better reason why header files exist. I'll go look it up.

  • @gabriellebtrc
    @gabriellebtrc 3 года назад

    5:58 2:43

  • @tips1483
    @tips1483 4 года назад +3

    3rd

  • @Nalhy
    @Nalhy 6 месяцев назад

    "no such file or directory"
    Fuck this shit, honestly