Yuav Txhaj Ib Rab Koob Li Cas

Cov txheej txheem:

Yuav Txhaj Ib Rab Koob Li Cas
Yuav Txhaj Ib Rab Koob Li Cas

Video: Yuav Txhaj Ib Rab Koob Li Cas

Video: Yuav Txhaj Ib Rab Koob Li Cas
Video: Koj nyiam hom li cas by Koob Meej Yaj, New Song ( 8/11/2020 ) 2024, Kaum ib hlis
Anonim

Arrays yog cov qauv yooj yim thiab siv tau ntawm xaj kom khaws cov ntaub ntawv. Lawv siv nyob rau hauv yuav luag txhua qhov khoos phis tawj. Feem ntau, cov ntaub ntawv hauv lawv tau tsim tawm thaum lub sijhawm ua haujlwm ntawm daim ntawv thov. Tab sis qee zaus koj yuav tsum nkag mus rau hauv ib qho array, tau txais cov ntaub ntawv los ntawm ib qho lossis lwm qhov chaw.

Yuav txhaj ib rab koob li cas
Yuav txhaj ib rab koob li cas

Tsim nyog

  • - ntawv nyeem editor lossis IDE;
  • - C ++ compiler.

Cov Lus Qhia

Kauj ruam 1

Nkag mus rau ib qho kev ua kom yuam kev rau tus neeg siv rau cov ntaub ntawv. Laij lossis nug txog pes tsawg lub ntsiab lus kom nkag mus. Tsim ib qho array ntawm qhov loj me uas xav tau. Ntxiv ib lub voj mus rau qhov chaw xav tau nyob rau hauv qhov program code kom iterate tshaj txhua lub ntsiab lus. Hauv lub voj, nug cov ntaub ntawv rau txhua yam khoom, xyuas seb lub tswv yim raug lawm. Qhov ntau txhais tau siv tau los ua cov ntaub ntawv nkag. Kev siv scanf thiab wscanf lub luag haujlwm ntawm lub tsev qiv ntawv C yog txoj hauv kev qub. Txawm li cas los xij, cov haujlwm no tsis nyab xeeb. Tsis tiv thaiv teeb meem dhau mus yuav ua rau muaj qhov yuam kev ruaj ntseg. C ++ ntws tso tawm cov tswv yim yooj yim thiab nyab xeeb, tab sis lawv kuj muaj qhov tsis zoo. Cov piv txwv yooj yim tshaj plaws ntawm txhawm rau sau ib qho qauv siv cov qauv ntsuas tawm tswv yim yuav zoo li qhov no: rau cov menyuam [10]; rau (rau cov menyuam = =; i <10; kuv ++) {std:: cout

Kauj ruam 2

Nkag mus rau hauv kab ntawv los ntawm cov ntaub ntawv. Siv cov qauv tswv yim (fscanf, fwscanf) thiab cov kwj khoom (xws li ifstream) siv cov kev nyeem ua lej yooj yim. Taug cov tswv yim yuam kev nrog qhov tsis zoo, swb, zoo, rdstate txoj kev thaum siv ntws. Qhov piv txwv yooj yim ntawm kev nyeem cov ntaub ntawv los ntawm cov ntawv yuav zoo li no: rau cov menyuam [10]; std:: ifstream oFileStream ("filename.txt"); yog (! oFileStream.fail ()) {rau (rau cov menyuam = 0; (i> aNumbers ;} lwm tus std:: cout

Kauj ruam 3

Nkag mus rau hauv kab ntawv ncaj qha mus rau qhov program code ua cov ntaub ntawv zoo li qub. Siv kab ntawv kev nyeem cov tsiaj ntawv los pib cov kab lus sib txawv. Piv txwv li, ib qho array ntawm qhov tseem ceeb ntawm qhov tsis muaj qhov ntev ntev, uas yog tus tswv cuab zoo li qub ntawm chav kawm, thiab tshaj tawm raws li: chav kawm CMyClass {… zoo li qub const rau m_anMyArray; …}; Yuav tsum tau pib ua raws li hauv qab no: const int CMyClass:: m_anMyArray = {10, 20, 30, 40}; Siv cov qauv no, koj tuaj yeem nkag mus rau arrays ntawm cov qauv ntawm txhua qhov tsis txaus ntseeg rau hauv cov cai ntawm txoj haujlwm.

Pom zoo: