
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ String Library - constructor
Description
It is used to construct a string object.and initializing its value depending on the constructor version used.
Declaration
Following is the declaration for std::string::string.
string();
Parameters
str − It is an another string object.
pos − It contains the position of first string character.
len − It contains the lenght of sub string.
s − Pointer to an array of characters.
n − It contains the information about number of characters to copy.
c − Character to fill the string.
first, last − It is an nput iterator to find the initial and final positions in a range.
il − It is an initializer_list object.
Return Value
none
Exceptions
Never throw any exceptiions.
Example
In below example for std::string::string.
#include <iostream> #include <string> int main () { std::string s0 ("initial string"); std::string s1; std::string s2 (s0); std::string s3 (s0, 8, 3); std::string s4 ("A character sequence", 6); std::string s5 ("Another character sequence"); std::string s6a (10, 'x'); std::string s6b (10, 42); std::string s7 (s0.begin(), s0.begin()+7); std::cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: " << s3; std::cout << "\ns4: " << s4 << "\ns5: " << s5 << "\ns6a: " << s6a; std::cout << "\ns6b: " << s6b << "\ns7: " << s7 << '\n'; return 0; }
The sample output should be like this −
s1: s2: initial string s3: str s4: A char s5: Another character sequence s6a: xxxxxxxxxx s6b: ********** s7: initial
string.htm
Advertisements