Gaisuwa masu sha'awar shirye-shirye da xalibai! A yau, za mu shiga cikin tafiya mai ban sha'awa zuwa tushen shirye-shiryen C++. Za mu gano sauƙi duk da haka tasirin ɗaya daga cikin mahimman abubuwan da ke tattare da shirye-shirye, wato, buga saƙon "Sannu Duniya". Kuna iya yin mamaki game da mahimmancin wani abu mai sauƙi kamar wannan, amma ku tuna, kowane babban gini yana farawa da tushe na asali.
Buga "Hello Duniya" a cikin C++
Da farko, bari mu dubi mafita ga babbar matsalarmu – ta yaya za mu iya buga “Hello Duniya” ta amfani da shirin C++? A ƙasa akwai taƙaitaccen lambar a duk kyawunta:
#include
amfani da sunaye std;
int babban () {
cout << "Sannu Duniya" << endl; dawo 0; } [/code]
Fahimtar Code
Yanzu da muka ga lambar, lokaci ya yi da za mu zurfafa zurfin fahimtar abin da kowane bangare ke ba da gudummawa a kai. Kuna iya tambayar buƙatar layukan lamba da yawa don ɗawainiya mai sauƙi. Koyaya, kowane layi na lambar yana taka muhimmiyar rawa.
Bari mu karya shi:
- Layin farko “#clude
” umarni ne na riga-kafi wanda ke gaya wa mai tarawa C++ don haɗa daidaitaccen fayil ɗin iostream. Wannan fayil ɗin yana ƙunshe da ma'anoni don tsara tsarin shigarwa da ayyukan fitarwa. - Layin "amfani da sunan sararin samaniya std;" yana ba mu damar amfani da sunaye daga filin suna 'std' ba tare da cancantar sunan da ke cikin lambar ba. Wannan da gaske yana sauƙaƙa lambar mu.
- Babban aikin yana aiki azaman wurin shigarwa don shirinmu. Duk shirye-shiryen C++ dole ne su kasance da babban aiki. Ma'anar kalmar "int" kafin babba tana nuna cewa babban() yana dawo da ƙimar lamba. Gabaɗaya, ana dawo da sifili daga aikin 'babban()' don nuna cewa shirin ya yi nasara.
- "cout << "Hello Duniya" << endl;' ita ce bayanin da ke da alhakin buga 'Hello World'. Anan, 'cout' ana amfani da shi tare da ma'aikacin sakawa (`<<)) don nuna abubuwan da muke so. 'endl' yana saka sabon layi.
- dawo 0; sanarwa shine "Matsalar fita" na shirin. A cikin sauki, shirin ya ƙare da wannan sanarwa.
Dakunan karatu Sun Shiga
A cikin wannan matsala mai sauƙi ta buga 'Hello World', babban ɗakin karatu da abin ya shafa shine 'iostream'. Wannan ɗakin karatu wani yanki ne na Babban Laburare na C++ wanda ke ba da aikin shigarwa da fitarwa ta amfani da rafuka.
Ayyukan da ke ciki
Babban ayyukan da ke cikin wannan snippet lambar sune 'babban()', 'cout', da 'endl'. Kowane ɗayan waɗannan ayyukan suna ba da gudummawa ta hanyarsu don ƙirƙirar yanki mai aiki wanda ke aiwatar da aikin da ke hannunsu.
a takaice, mu tawali'u "Hello, Duniya!" shirin, yayin da kawai mataki na asali a cikin shirye-shiryen C++, yana kwatanta mahimman sassa daban-daban da ke aiki tare, wanda ya ƙunshi umarni na farko, ɗakunan karatu, ayyuka, da haɗin gwiwa. Ta hanyar fahimtar wannan, muna kafa misali don fahimtar ƙarin hadaddun aikace-aikace yayin da muke ci gaba a cikin tafiyar shirye-shiryenmu.