OpenSCADAWiki:
Roman Savochenko
/
C Short All
/
part2
/part7
...
Home
|
Index
|
Changes
|
Comments
|
Users
|
Registration
|
Login
:
Password:
====2.7 Потоковая обработка строк <string>==== Для работы со строками в языке C++ предусмотрен шаблонный класс basic_string из которого определяется класс string: %%(php)typedef basic_string <char> string; typedef basic_string <wchar_t> string; \\для UNICODE%% Примеры инициализации строк: %%(php)string s1("Hello"); //Строка "Hello" string s2(8,x); //Восемь символов 'x' string month = "March"; //Строка "March" s = 'n' //символ 'n' cin >> s; //вводить в <s> getline(cin,s); //--//-- str1.assign(str2); str1[2] = 'r'; //Присвоить 'r' string s1(s2+"test");%% Для потоковой обработки строк используются классы: <ostringstream> %%(php)outstring << S1 << S2 << S3 << 2 << 3.58; cout << outstring.str(); instring >> S1 >> S2 >> i;%% =====2.7.1 Функции===== **operator==, !=, >, <, >=, <=** Операторы сравнения строк. **assign** //basic_string& assign (const basic_string& str, size_type pos = 0, size_type n = npos);// //basic_string& assign (const charT* s, size_type n);// //basic_string& assign (const charT* s);// //basic_string& assign (size_type n, charT c);// Создаёт новую строку из участка старой. **append** //basic_string& append(const basic_string& str, size_type pos = 0, size_type n = npos);// //basic_string& append (const charT* s, size_type n);// //basic_string& append (const charT* s);// //basic_string& append (size_type n, charT c);// //basic_string& append(~InputIterator first, ~InputIterator last);// Добавление к строке. **at** //reference at(size_type pos);// //const_reference at(size_type pos) const;// Получить символ по с индексом <POS>. **begin, end** //iterator begin ();// //iterator end ();// Возвращает итератор; **capacity** //size_type capacity() const;// Максимальный размер строки без увеличения памяти под строку. **compare** //int compare (const basic_string& str, size_type pos = 0, size_type n = npos) const;// //int compare (const charT* s, size_type pos, size_type n) const;// //int compare (const charT* s, size_type pos = 0) const;// Сравнение строк. **copy** //size_type copy (charT* s, size_type n, size_type pos = 0) const;// Копировать строку в адрес определённый указателем. **с_str** //const charT* c_str() const;// Возвращает указатель на строку с нулём в конце. **data** //charT* data()// Возвращает указатель на строку без нуля в конце. **empty** //bool empty() const;// Проверка строки на пустоту. **erase** //basic_string& erase(size_type pos = 0, size_type n = npos);// //iterator erase(iterator p);// //iterator erase(iterator f, iterator l);// Удаление всех символов начиная от указанной позиции. **begin, end** //iterator begin();// //iterator end();// Получение начального/конечного итератора. **find, rfind** //size_type find(const basic_string& str, size_type pos = 0) const;// //size_type rfind(const basic_string& str, size_type pos = npos) const;// Поиск сначала/конца строки. **find_first_of, find_last_of** //size_type find_first_of(const basic_string& str, size_type pos = 0) const;// //size_type find_last_of (const basic_string& str, size_type pos = npos) const;// Поиск сначала/конца строки одного из перечисленных символов. **find_first_not_of, find_last_not_of** //size_type find_first_not_of(const basic_string& str, size_type pos = 0) const;// //size_type find_last_not_of (const basic_string& str, size_type pos = npos) const;// Поиск сначала/конца первого символа отсутствующего в списке. **insert** //basic_string& insert(size_type pos1, const basic_string& str, size_type pos2 = 0, size_type n = npos);// Вставка в строку части другой строки. **length, size** //size_type length() const;// //size_type size() const;// Длина строки. **max_size** //size_type max_size() const;// Максимальная длина строки. **replace** //basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2 = 0, size_type n2 = npos);// Заменить участок строки. **resize** //void resize (size_type n, charT c);// //void resize (size_type n);// Изменить длину строки. **substr** //basic_string substr(size_type pos = 0, size_type n = npos) const;// Получение части строки; **swap** //void swap (basic_string &s)// Перестановка строк.
Please type the word you read in the image: