This document introduces C++ strings and I/O streams. It shows how to compose an email address from a name and domain, append to strings, extract substrings, and modify strings. Functions are defined to output integers and strings to stdout. The document also demonstrates reading user input, including integers and strings, from stdin. Finally, it defines a struct with name and number fields, overloads insertion and extraction operators for the struct, and uses these operators to read and write structs to I/O streams.
The document discusses patterns and techniques for writing cross-platform Objective-C code. It describes using a strategy pattern to abstract platform-specific code behind a common interface. Classes like O2LPerson would delegate platform-specific behavior to subclasses like O2LPersonStrategyMac and O2LPersonStrategyiOS. It also provides examples of checking for features at runtime through techniques like responding to selectors, class existence checks, and dlopen.
The document introduces several C++ standard library utilities including:
1) Chrono for measuring elapsed time between events in milliseconds.
2) Numeric limits for querying properties of fundamental types like the smallest positive float.
3) Iterator tags and overloading algorithms like sort based on iterator categories.
4) Type traits like is_arithmetic to check properties of types.
5) Pair and tuple for grouping multiple objects of different types.
The document discusses parallel programming concepts in C++ including threads, synchronization using mutexes, condition variables for producer-consumer problems, and futures/promises for asynchronous function calls. It provides examples of spawning threads to execute functions concurrently, protecting shared data with mutexes, notifying condition variables to signal events, and getting values from futures after asynchronous tasks have completed.
The document provides examples of using various C++ standard library containers and algorithms. It shows how to define a phone book using map and unordered_map containers and retrieve phone numbers by name. It also lists different container types and their characteristics, and provides examples of algorithms like sort, find, copy, and equal_range.
This document discusses containers like vectors and lists in C++. It provides examples of declaring and initializing vectors with different data types. Functions are demonstrated for printing, inserting, and searching elements in a vector. The document also contains examples of declaring and iterating through lists, and functions for inserting and removing elements from a list.
The document introduces the C++ standard library and its main components. It discusses key elements like strings, I/O streams, containers and algorithms. It also mentions how the standard library provides runtime language support, the C standard library, and utilities to support common programming tasks like string handling, I/O, containers, algorithms, numerical computations, concurrency, metaprogramming and smart pointers.
The document describes C++ templates and how they can be used to define generic containers like Vector that work for different element types. It shows how to define a Vector class with a template parameter T for the element type. It also demonstrates how templates can be used to write algorithms that work on different container types by extracting the element type. Functions, classes, and type aliases can all be templated.
The document discusses patterns and techniques for writing cross-platform Objective-C code. It describes using a strategy pattern to abstract platform-specific code behind a common interface. Classes like O2LPerson would delegate platform-specific behavior to subclasses like O2LPersonStrategyMac and O2LPersonStrategyiOS. It also provides examples of checking for features at runtime through techniques like responding to selectors, class existence checks, and dlopen.
The document introduces several C++ standard library utilities including:
1) Chrono for measuring elapsed time between events in milliseconds.
2) Numeric limits for querying properties of fundamental types like the smallest positive float.
3) Iterator tags and overloading algorithms like sort based on iterator categories.
4) Type traits like is_arithmetic to check properties of types.
5) Pair and tuple for grouping multiple objects of different types.
The document discusses parallel programming concepts in C++ including threads, synchronization using mutexes, condition variables for producer-consumer problems, and futures/promises for asynchronous function calls. It provides examples of spawning threads to execute functions concurrently, protecting shared data with mutexes, notifying condition variables to signal events, and getting values from futures after asynchronous tasks have completed.
The document provides examples of using various C++ standard library containers and algorithms. It shows how to define a phone book using map and unordered_map containers and retrieve phone numbers by name. It also lists different container types and their characteristics, and provides examples of algorithms like sort, find, copy, and equal_range.
This document discusses containers like vectors and lists in C++. It provides examples of declaring and initializing vectors with different data types. Functions are demonstrated for printing, inserting, and searching elements in a vector. The document also contains examples of declaring and iterating through lists, and functions for inserting and removing elements from a list.
The document introduces the C++ standard library and its main components. It discusses key elements like strings, I/O streams, containers and algorithms. It also mentions how the standard library provides runtime language support, the C standard library, and utilities to support common programming tasks like string handling, I/O, containers, algorithms, numerical computations, concurrency, metaprogramming and smart pointers.
The document describes C++ templates and how they can be used to define generic containers like Vector that work for different element types. It shows how to define a Vector class with a template parameter T for the element type. It also demonstrates how templates can be used to write algorithms that work on different container types by extracting the element type. Functions, classes, and type aliases can all be templated.
The document discusses copy and move semantics in C++. It provides examples of copy initialization, copy assignment, and copy constructors that make copies of objects. It then introduces move semantics using move constructors and move assignment that allow efficiently transferring resources from one object to another. The document shows how to implement move operations for a Vector class and demonstrates their use. It also shows how to delete copy and move operations to prevent objects from being copied or moved.
This document discusses abstract data types and containers in C++. It defines an abstract Container class with pure virtual functions for accessing elements and size. It then shows two classes, Vector_container and List_container, that implement the Container interface to allow a function to generically use different container types.
This document discusses C++ data types including fundamental types like int and double, user-defined types like structures and classes, and enumerations. It provides examples of defining a struct called Vector to represent an array, using Vector in a function, and converting Vector to a class. It also shows an example of an enumerator called Color and how to implement operator overloading for a prefix increment operator on an enum.
The document discusses arrays, pointers, references in C++. It defines arrays as collections of elements that can be accessed using indices starting from 0. It shows examples of declaring and initializing arrays, looping through arrays, copying arrays, printing array elements, and incrementing array elements. It also defines pointers as variables that store the address of another variable. It discusses pointer arithmetic and pointer to functions. It defines references as aliases to existing variables that must be initialized.
The document discusses different conditional and looping structures in C++ including if/else statements, switch statements, while loops, do-while loops, and for loops. It provides examples of a function called accept that uses these structures to prompt the user for input and return true if they enter 'y' or false otherwise, allowing for multiple tries.
DDS Security Version 1.2 was adopted in 2024. This revision strengthens support for long runnings systems adding new cryptographic algorithms, certificate revocation, and hardness against DoS attacks.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
Odoo ERP software
Odoo ERP software, a leading open-source software for Enterprise Resource Planning (ERP) and business management, has recently launched its latest version, Odoo 17 Community Edition. This update introduces a range of new features and enhancements designed to streamline business operations and support growth.
The Odoo Community serves as a cost-free edition within the Odoo suite of ERP systems. Tailored to accommodate the standard needs of business operations, it provides a robust platform suitable for organisations of different sizes and business sectors. Within the Odoo Community Edition, users can access a variety of essential features and services essential for managing day-to-day tasks efficiently.
This blog presents a detailed overview of the features available within the Odoo 17 Community edition, and the differences between Odoo 17 community and enterprise editions, aiming to equip you with the necessary information to make an informed decision about its suitability for your business.
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfUndress Baby
The quest for the best AI face swap solution is marked by an amalgamation of technological prowess and artistic finesse, where cutting-edge algorithms seamlessly replace faces in images or videos with striking realism. Leveraging advanced deep learning techniques, the best AI face swap tools meticulously analyze facial features, lighting conditions, and expressions to execute flawless transformations, ensuring natural-looking results that blur the line between reality and illusion, captivating users with their ingenuity and sophistication.
Web:- https://undressbaby.com/
Do you want Software for your Business? Visit Deuglo
Deuglo has top Software Developers in India. They are experts in software development and help design and create custom Software solutions.
Deuglo follows seven steps methods for delivering their services to their customers. They called it the Software development life cycle process (SDLC).
Requirement — Collecting the Requirements is the first Phase in the SSLC process.
Feasibility Study — after completing the requirement process they move to the design phase.
Design — in this phase, they start designing the software.
Coding — when designing is completed, the developers start coding for the software.
Testing — in this phase when the coding of the software is done the testing team will start testing.
Installation — after completion of testing, the application opens to the live server and launches!
Maintenance — after completing the software development, customers start using the software.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
The document discusses copy and move semantics in C++. It provides examples of copy initialization, copy assignment, and copy constructors that make copies of objects. It then introduces move semantics using move constructors and move assignment that allow efficiently transferring resources from one object to another. The document shows how to implement move operations for a Vector class and demonstrates their use. It also shows how to delete copy and move operations to prevent objects from being copied or moved.
This document discusses abstract data types and containers in C++. It defines an abstract Container class with pure virtual functions for accessing elements and size. It then shows two classes, Vector_container and List_container, that implement the Container interface to allow a function to generically use different container types.
This document discusses C++ data types including fundamental types like int and double, user-defined types like structures and classes, and enumerations. It provides examples of defining a struct called Vector to represent an array, using Vector in a function, and converting Vector to a class. It also shows an example of an enumerator called Color and how to implement operator overloading for a prefix increment operator on an enum.
The document discusses arrays, pointers, references in C++. It defines arrays as collections of elements that can be accessed using indices starting from 0. It shows examples of declaring and initializing arrays, looping through arrays, copying arrays, printing array elements, and incrementing array elements. It also defines pointers as variables that store the address of another variable. It discusses pointer arithmetic and pointer to functions. It defines references as aliases to existing variables that must be initialized.
The document discusses different conditional and looping structures in C++ including if/else statements, switch statements, while loops, do-while loops, and for loops. It provides examples of a function called accept that uses these structures to prompt the user for input and return true if they enter 'y' or false otherwise, allowing for multiple tries.
DDS Security Version 1.2 was adopted in 2024. This revision strengthens support for long runnings systems adding new cryptographic algorithms, certificate revocation, and hardness against DoS attacks.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
Odoo ERP software
Odoo ERP software, a leading open-source software for Enterprise Resource Planning (ERP) and business management, has recently launched its latest version, Odoo 17 Community Edition. This update introduces a range of new features and enhancements designed to streamline business operations and support growth.
The Odoo Community serves as a cost-free edition within the Odoo suite of ERP systems. Tailored to accommodate the standard needs of business operations, it provides a robust platform suitable for organisations of different sizes and business sectors. Within the Odoo Community Edition, users can access a variety of essential features and services essential for managing day-to-day tasks efficiently.
This blog presents a detailed overview of the features available within the Odoo 17 Community edition, and the differences between Odoo 17 community and enterprise editions, aiming to equip you with the necessary information to make an informed decision about its suitability for your business.
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfUndress Baby
The quest for the best AI face swap solution is marked by an amalgamation of technological prowess and artistic finesse, where cutting-edge algorithms seamlessly replace faces in images or videos with striking realism. Leveraging advanced deep learning techniques, the best AI face swap tools meticulously analyze facial features, lighting conditions, and expressions to execute flawless transformations, ensuring natural-looking results that blur the line between reality and illusion, captivating users with their ingenuity and sophistication.
Web:- https://undressbaby.com/
Do you want Software for your Business? Visit Deuglo
Deuglo has top Software Developers in India. They are experts in software development and help design and create custom Software solutions.
Deuglo follows seven steps methods for delivering their services to their customers. They called it the Software development life cycle process (SDLC).
Requirement — Collecting the Requirements is the first Phase in the SSLC process.
Feasibility Study — after completing the requirement process they move to the design phase.
Design — in this phase, they start designing the software.
Coding — when designing is completed, the developers start coding for the software.
Testing — in this phase when the coding of the software is done the testing team will start testing.
Installation — after completion of testing, the application opens to the live server and launches!
Maintenance — after completing the software development, customers start using the software.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
Measures in SQL (SIGMOD 2024, Santiago, Chile)Julian Hyde
SQL has attained widespread adoption, but Business Intelligence tools still use their own higher level languages based upon a multidimensional paradigm. Composable calculations are what is missing from SQL, and we propose a new kind of column, called a measure, that attaches a calculation to a table. Like regular tables, tables with measures are composable and closed when used in queries.
SQL-with-measures has the power, conciseness and reusability of multidimensional languages but retains SQL semantics. Measure invocations can be expanded in place to simple, clear SQL.
To define the evaluation semantics for measures, we introduce context-sensitive expressions (a way to evaluate multidimensional expressions that is consistent with existing SQL semantics), a concept called evaluation context, and several operations for setting and modifying the evaluation context.
A talk at SIGMOD, June 9–15, 2024, Santiago, Chile
Authors: Julian Hyde (Google) and John Fremlin (Google)
https://doi.org/10.1145/3626246.3653374
Takashi Kobayashi and Hironori Washizaki, "SWEBOK Guide and Future of SE Education," First International Symposium on the Future of Software Engineering (FUSE), June 3-6, 2024, Okinawa, Japan
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
7. 01. void h(int i)
02. {
03. cout << "the value of i is ";
04. cout << i;
05. cout << 'n';
06. }
the value of i is 10
01. void h2(int i)
02. {
03. cout << "the value of i is " << i << 'n';
04. }
8. 01. void f()
02. {
03. int i;
04. cin >> i; // read an integer into i
05. double d;
06. // read a double-precision floating-point number into d
07. cin >> d;
08. }
01. void hello()
02. {
03. cout << "Please enter your namen";
04. string str;
05. cin >> str;
06. cout << "Hello, " << str << "!n";
07. }
11. 01. // read { "name" , number } pair. Note: formatted with { " " , and }
02. istream& operator>>(istream& is, Entry& e)
03. {
04. char c, c2;
05. if (is>>c && c=='{' && is>>c2 && c2=="") { // start with a { "
06. // the default value of a string is the empty string: ""
07. string name;
08. while (is.get(c) && c!='"') // anything before a " is part of the name
09. name+=c;
10. if (is>>c && c==',') {
11. int number = 0;
12. if (is>>number>>c && c=='}') { // read the number and a }
13. e = {name,number}; // assign to the entry
14. return is;
15. }
16. }
17. }
18. is.setf(ios_base::failbit); // register the failure in the stream
19. return is;
20. }
12. { "John Marwood Cleese" , 123456 }
{"Michael Edward Palin",987654}
01. for (Entry ee; cin>>ee; ) // read from cin into ee
02. cout << ee << 'n'; // write ee to cout
{"John Marwood Cleese", 123456}
{"Michael Edward Palin", 987654}
Editor's Notes
در این ویدیو ادامه ی بحث کتابخونه استاتدارد رو پی می گیریم و در مورد string و stream ها صحبت می کنم.
کتابخونه استاندارد برای کار با رشته ها یه type به نام string رو فراهم کرده. String یه سری عملیات پرکاربرد و مفید برای کار با رشته ها داره.
مثلا برای concat کردن رشته ها خیلی راحت می شه از + استفاده کرد. بعد از فراخوانی تابع compose مقدار Addr برابر dmr@bell-labs.com خواهد شد. اپراتور + برای انواع مختلفی از ورودی ها تعریف شده مثلا می تونید 2 تا string رو با هم جمع کرد یا یه string با یه c-style string و یا کاراکتر با string رو جمع کرد و بهم concat کرد. همین طور دارای move constructor هم هست و اجازه می ده که حتی stringهای بزرگ رو by-value از تابع return کرد بدون اینکه کپی صورت بگیره.
در بیشتر برنامه ها ما نیاز داریم که به انتهای یه string یه چیزی رو concat کنیم. برای این کار اپراتور += برای string نوشته شده و به راحتی می تونیم ازش استفاده کنیم. خط 3 و خط 4 باهم معادل هستند یعنی هم می تونید از + برای concat کردن استفاده کنید و هم از += استفاده کنید. اما دومی بهتره چون صرحتر داره مفهوم اضافه شدن یه کاراکتر رو به انتهای رشته نشون میده و efficient تره.
Stringها mutable هستند یعنی اینکه میتونیم مقدار اون رو تغییر بدیم. همینطور علاوه بر اپراتور های =، +=؛ اپراتور های subscript و توابع مفیدی برای کار با زیر رشته ها و substringها داره و قابلیت کار با زیر رشته ها و دستکاری کردن اونا رو بما میده.
تابع substr یه کپی از زیر رشته ای که می خوایم رو بر می گردونه. اولین آرگمان indexیی هست که می خوایم از اونجا زیر رشته شروع بشه. و دومین آرگمان طول زیر رشته هست و Index هم از صفر شروع میشه پس زیر رشته ای که توسط این خط برگردونده میشه stroustrup خواهد بود.
تابع replace یه زیر رشته رو با یه زیر رشته ی دیگه جایگزین می کنه. و مشابه substr اولین آرگمان index شروع زیر رشته، آرگمان دوم طول زیر رشته و سومین آرگمان رشته ای که می خوایم جایگزین کنیم هست. با اجرای این خط niels با nicholas جایگزین میشه. نکته ای که هست اینه که برای replace کردن یه زیر رشته با یه زیر رشته ی دیگه لازم نیست که size اونا با هم برابر باشه و string برای ما عملیات جا باز کردن و یا کوچیک کردن رو انجام میده.
در آخر هم اولین کاراکتر رشته رو با استفاده از تابع toupper به حرف بزرگ تبدیل کردیم.
ما میتونیم stringها رو با هم مقایسه کنیم. همین طور یه string رو با یه رشته ی ثابت یا Literal هم می تونیم مقایسه کنیم.
می تونیم 2 تا string رو با هم مقایسه کنیم که آیا با هم برابر هستند یا نه؟
و اینجا هم string رو با یه literal مقایسه کردیم. توی C++ به رشته ی Yes میگیم لیترال. در مورد Literalها در فصل 36 کتاب کامل بحث شده.
کتابخونه استاندارد ورودی و خروجی های فرمت بندی شده رو با iostream برای ما فراهم کرده. قبلا کارکردن با اون رو دیده بودیم و از cout و cin استفاده کرده بودیم. اما بقیه ورودی خروجی ها مثل کار با کارت گرافیک و یا GUI جزء استاندارد ISO نیستند و باید از کتابخونه های دیگه استفاده کرد.
در کتابخونه Iostream با استفاده از Cout ما می تونسم تمام built-in typeها رو روی خروجی چاپ کنیم. اپراتور << که اولین ورودیش ostream باشه به عنوان put to شناخته میشه و برای خروجی دادن استفاده میشه. مثلا برای اینکه عدد 10 رو خروجی بدیم به این صورت عمل می کنیم. عدد 10 تبدیل میشه به 2تا کاراکتر 1 و 0 و روی صفحه چاپ میشن.
مثال بالا با مثال پایین برابر هستند در هر 2 مثال یه عدد integer رو به خروجی فرستادیم. در اولی یه عدد ثابت و در دومی یه متغییر رو روی خروجی چاپ کردیم.
قبلا دیده بودیم که می تونستیم typeهای مختلفی رو با هم ترکیب کنیم و به خروجی بفرستیم مثلا می تونیم یه string رو به خروجی بفرستیم. بعد یه integer رو و بعد یه کاراکتر رو به خروجی بفرستیم.
خروجی این کد به این صورت خواهد شد.
ولی خیلی زود از اینکه همش cout رو تکرار کنیم خسته میشیم پس می یایم کل تابع h رو توی یک خط می نویسیم و خروجی هایی که به هم مرتبط هستند رو در کنار هم قرار میدیم. تابع h2 دقیقا همون خروجیی رو میسازه که تابع h میسازه.
کتابخونه استاندارد برای ورودی istream رو پیشنهاد میده. مشابه ostream، istream هم روی built-in typeها تعریف شده و میتونه اونا رو بخونه و مقدار اونا رو برگردونه.
اپراتور >> شیفت به راست برای خوندن از ورودی تعریف شده که به عنوان get from استفاده میشه. ما از Cin استفاده کرده بودیم و از ورودی مقادیر رو خونده بودیم.
عملوند سمت راست >> مشخص میکنه که از ورودی چه چیزی رو می خوایم بخونیم.
این خط یه عدد صحیح رو از ورودی می خونه مثلا 1234 و توی i ذخیره می کنه.
و بعد یه عدد ممیز شناور رو می خونه و در d ذخیره می کنه.
بعضی وقتا ما می خوایی یه سری از کاراکتر ها رو بخونیم و اونا رو بریزیم توی string .
برای اینکار کافیه چیزی که جلوی cin منویسیم typeش stringباشه. Cin از ورودی یه string رو میخونه و بر می گردونه. به صورت پیش فرض withespace مثل space یا tab باعث میشن که خوندن کاراکتر ها تموم بشه و به عنوان string برگردونده بشه.
برای اینکه بتونیم رشته هایی رو از ورودی بخونیم که وسطشون space داشته باشن باید از getline() استفاده کنیم. تابع getline یک خط از ورودی رو میخونه و برمیگردونه و اگه وسط خط space باشه اونا رو هم میخونه تا اینکه به کاراکتر new line یا enter برسه. آخرین کاراکتر که \n هست توسط cin حذف میشه و بقیه خط از ابتدا تا کاراکتر قبل از \n برگردونده میشه. String این ویژگی رو داره که ورودی شما هر چقدر باشه به همون اندازه حافظه میگیره و ورودی رو در خودش ذخیره میکنه و نیازی نیست که محاسبه ای برای ماکزیموم size ورودی انجام بدیم.
تا اینجا ما برای خوندن و چاپ کردن از built-in typeها استفاده کردیم. علاوه بر built-in typeها می تونیم typeهای تعریف شده توسط خودمون رو هم از ورودی بخونیم و یا در خروجی چاپ کنیم.
یه مثال ساده برای این کار با هم خواهیم دید. فرض کنید که می خوایم یه دفترچه تلفن ساده بسازیم .یه struct به نام entry می نویسیم که نام و شماره رو ذخیره کنه.
برای اینکه بتونیم entry رو در خروجی چاپ کنیم باید یه اپراتور شیفت به چپ یا put to بنویسیم و داخل اون هر فرمتی که تمایل داریم خروجی بر اساس اون باشه رو تولید کنیم.
این اپراتور ورودی اولش یه reference به یه ostream هست
و ورودی دومش یه const reference به Entry هست و در بدنش هم میاد name و number رو چاپ میکنه و اول و آخر اون هم یه آکولاد باز و یه آکولاد بسته می ذاره.
اما نوشتن اپراتور ورودی برای entry یکم پیچیده تره چون باید چک کنیم که وردی کاربر با فرمتی که انتظار داریم یکسان باشه و خطاهایی که ممکنه در هنگام ورود اطلاعات رخداده باشه رو هم در نظر بگیریم.
خروجی اپراتور باید همون refence از istream که در ورودی دریافت میکنه باشه. از همین is میتوینم برای چک کردن اینکه خطایی رخ داده یا نه استفاده کنیم. اگه خطایی رخ نداده باشه فقط اونو بر می گردونیم.
در غیر این صورت می تونیم flag یی رو set کنیم که بگیم یه خطا اتفاق افتاده.
وقتی توی شرط if از is >> c استفاده می کنیم به این معنیه که آیا موفق شدیم که یه کاراکتر رو بخونیم و مقدار اونو در c ذخیره کنیم یا نه؟ این دستور یه کاراکتر رو می خونه و به صورت پیش فرض از روی کاراکتر های whitespace میپره.
تابع is.get(c) هم یه کاراکتر از ورودی می خونه و مقدار اون رو در c ذخیره می کنه اما بر خلاف get from به صورت پیش فرض از روی whitespaceها نمیپره و اونا رو هم بر میگردونه. ما در این حلقه نیاز داریم که whitespaceها رو هم ذخیره کنیم چون ممکنه داخل اسمی که می خوایم از ورودی دریافت کنیم space وجود داشته باشه. ما با get from می تونیم از روی spaceهایی که خارج از اسم هستند بپریم ولی با تابع get؛ spaceهایی که داخل اسم هستند رو ذخیره کنیم.
حالا می تونیم از اون اپراتور های put to و get from که نوشتیم استفاده کنیم.
فرض کنید که ورودی ما به این صورت باشه. خط اول ورودی یه space بعد از آکولاد باز هست و یه tab هم قبل از آکولاد بسته هست و حظ دوم ورودی هم هیچ spaceیی نداریم.
می تونیم توی main از for برای خوندن هر تعداد ورودی از نوع entry استفاده کنیم و ورودی رو که می خونیم دوباره روی خروجی چاپ کنیم. از cin میخونیم و با cout در خروجی چاپ می کنیم.
خروجی این حلقه به این صورت خواهد شد.
در این ویدیو string و io streamها رو معرفی کردم. و پر کار برد ترین امکانات هر کدوم رو توضیح دادم.