DEV Community

islomAli99
islomAli99

Posted on

1

Maxsus belgilar | C++ boshlang'ich

string va maxsus belgilar

Avvalgi postimizda yozganimizdek, C++ tilida tekstlar string deb ataladi va qo'shtirnoq ichida " " 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 ishlatsa, string tugaganini anglatadi.

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

cout << "U \"zo'r\" bola." << endl;
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 string ni chop etishda \n bor joydan boshlab keyingi qator o'tib ketadi.
cout << "Salom\nDunyo" << endl;

--------------natija-------------
Salom
Dunyo
Enter fullscreen mode Exit fullscreen mode
  1. \t - Tab (tabulation)
  • 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
  1. \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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay