Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test string
//clang 6.0.0 #include <iostream> #include <string> #include <sstream> using namespace std; int main() { /* string s1("Hello"); string s2("Hello", 3); string s3(s1, 2); string s4(s1, 2, 2); string s5(5, 'a'); cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; cout << s4 << endl; cout << s5 << endl; */ /* string s1 = "goodbyte"; cout << s1.size() <<" " << s1.length() << endl; cout << s1.capacity() << endl; s1.shrink_to_fit(); cout << s1.capacity() << endl; s1.resize(3, 'x'); cout << s1 << ":" << endl; */ /* //string element access string s1 = "goodbye"; s1.pop_back(); s1.push_back('z'); cout << s1 << endl; string s3(s1.begin(), s1.begin()+3); cout << s3 << endl; string s2 = "dragon land"; s1.assign(s2); cout << s1 << endl; s1.append(" def"); cout << s1 << endl; s1.insert(2, "mountain", 4); cout << s1 << endl; s1.replace(2, 5, s3, 1, 2); cout << s1 << endl; s1.erase(2, 2); cout << s1 << endl; cout << s1.data() << endl; s1.swap(s3); cout << s1 << endl; */ /* // copy, find, compare string s1 = "abcdefg"; char buf[20]; size_t len = s1.copy(buf, 3, 2); cout << buf << " " << len << endl; s1 = "if a job is worth doing , it is worth doing well"; size_t found = s1.find("doing"); cout << found << endl; found = s1.find("doing", 20); cout << found << endl; found = s1.find_first_of("doing"); found = s1.find_last_of("doing"); cout << found << endl; string s2 = "aest"; s1.compare(s2); // if s1 > s2 return positive cout << s1.compare(s2) << endl; cout << s1 + s2 << endl; */ /* //cout << to_string(2.3e7) << endl; string s1 = "190.9 monkey"; int i = stoi(s1); cout << stoi(s1) << " " << stol(s1) << " " << stod(s1) << " " << stof(s1) << endl; */ /* string s1 = "variety is the spice of life."; int num = count(s1.begin(), s1.end(), 'e'); cout << num << endl; num = count_if(s1.begin(), s1.end(), [](char c) { return c < 'e';}); cout << num << endl; s1 = "goodness is better than beauty."; string::iterator itr = search_n(s1.begin(), s1.begin()+20, 2, 's'); cout << itr - s1.begin() << endl; s1.erase(itr, itr+5); cout << s1 << endl; s1.replace (itr, itr+3, "good day"); cout << s1 << endl; replace(s1.begin(), s1.end(), 'a', 'b'); cout << s1 << endl; string s2 = "laskdfalsjfaslkfjaslfgjaslkdasldgasldgf"; transform(s1.begin(), s1.end(), s2.begin(), [](char c) {if (c < 'n') return 'a'; else return 'z';}); cout << s2 << endl; s1 = "abcdefg"; rotate(s1.begin(), s1.begin()+3, s1.end()); cout << s1 << endl; */ stringstream ss; ss << 89 << " Hex: " << hex << 89<< " Oct: " << oct << 89; cout << ss.str() << endl; int a, b, c; string s1; ss >> hex >> a; cout << a << endl; ss >> s1; cout << s1 << endl; return 0; }
run
|
edit
|
history
|
help
0
MY FIRST OBJECT ORIENTED PROGRAM
mpi_distributed_sort
A
khcmknhc
UTF-8 in C++11
Namespace scope qualifier
Pointer array
Merge Sort
pack expansion
Te