Maxsus belgilar | C++ boshlang'ich

wahidustoz

Wahid Abduhakimov

Posted on March 18, 2022

Maxsus belgilar | C++ boshlang'ich

string va maxsus belgilar

Avvalgi postimizda yozganimizdek, C++ tilida tekstlar string deb ataladi va qo'shtirnoq " " orasida yoziladi.

cout << "Salom dunyo!" << endl;
Enter fullscreen mode Exit fullscreen mode

1️⃣ \ - escape character

  • ushbu belgi string/tekst ichida maxsus komandalar/belgilar yozish uchun ishlatiladi.

string ichida yozish mumkin bo'lmagan ba'zi belgilar mavjud. Masalan: U "zo'r" bola. deb chop etish uchun C++ da "U "zo'r" bola." deb yozish xatolik beradi. Bunga sabab string ichida " belgisi ishlatisa, string tugaganini anglatadi.

string ichida shunga o'xshash ta'qiqlangan belgilarni yozish uchun \ ishlatiladi.

cout << "U \"zo'r\" bola." << endl;

------------natija-------------
U "zo'r" bola.
Enter fullscreen mode Exit fullscreen mode

\ belgisini o'zini chop etish uchun nima qilamiz 🤔?

\\ qilib yoziladi

cout << "Bugun \\ belgisini asl kuchini ko'rdik!" << endl;

------------natija-------------
Bugun \ belgisini asl kuchini ko'rdik!
Enter fullscreen mode Exit fullscreen mode

2️⃣ \n - yangi qator

  • ushbu maxsus belgi string register ichiga yozilsa, shu stringni chop etishda \n bor joydan boshlab keyingi qator o'tib ketadi.
cout << "Salom\ndunyo" << endl;

------------natija-------------
Salom
dunyo
Enter fullscreen mode Exit fullscreen mode

3️⃣ \t- TAB

  • string ichiga yozilganda tekst ichiga TAB bo'sh joy chop etadi
cout << "olma\tanor\tbexi" << endl;

------------natija-------------
olma   anor   bexi
Enter fullscreen mode Exit fullscreen mode

4️⃣ \b- backspace

  • oxirgi chop etilgan belgini o'chiradi
cout << "Salom\b" << endl;

------------natija-------------
Salo
Enter fullscreen mode Exit fullscreen mode

5️⃣ \r- carriage return

  • chop etilayotgan qatorda kursorni qator boshiga olib keladi. Yana chop etishda davom etilsa avval yozilgan tekstlarni o'chirib ustiga yozib yuboradi
cout << "Github 'vashshe' malades 🌟\rIlmhub" << endl;

------------natija-------------
Ilmhub 'vashshe' malades 🌟
Enter fullscreen mode Exit fullscreen mode

Topshiriqlar 🎖

  1. Qiyudagi kod nima chop etadi?
cout << "bexi\ranor\rolma\b" << endl;
Enter fullscreen mode Exit fullscreen mode
  1. Quyidagi stringni C++ da chop eting.
\    /\
 )  ( ')
(  /  )
 \(__)|
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
wahidustoz
Wahid Abduhakimov

Posted on March 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

setw() & setfill() | C++ boshlang'ich
beginners setw() & setfill() | C++ boshlang'ich

March 12, 2024

Maxsus belgilar | C++ boshlang'ich
beginners Maxsus belgilar | C++ boshlang'ich

March 18, 2022