Server IP : 172.16.15.8 / Your IP : 3.145.91.152 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/brmorrison/../drsparks/212/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// // File: cstring2.cpp // // Goal: Test the concepts/usages of c-string // // #include <iostream> using namespace std; int main() { // C++ string string str; // C-string: char. array with '\0' (NULL-char.) termination char str1[21]; // c-string str1 // input cout << "Input for s-string: "; cin >> str1; // c-string input // p.152, use strcopy for string assignment for C-string // str1 = "John Wang"; // invalid for C-string strcpy(str1, "John Wang"); str = "CS 212"; // valid for C++ string // debug system("clear"); cout << "\n\nDebug C-string --- str1[1]: " << str1[1] << endl; cout << "Debug C++ string --- str[0]: " << str[0] << endl; // out // system("clear"); // clear screen cout << "C++ string: " << str << "\n"; cout << "C-string: " << str1 << '\n'; // String length (p.156): C++ string: str.length(); // C-string: strien(str1) cout << "Length for C++ string: " << str.length() << "\n" << "Length for C-string: " << strlen(str1) << '\n'; // comparison (p.156): C++: >, <, etc.; // C-string: strcmp(...)>0, <0, etc. // Q: Compare if str1 is greater than "VWC". if so, display "Yes" // if no, display "No." if ( strcmp(str1, "VWC") > 0 ) cout << "Yes."; else cout << "No."; cout << "\n\n\nDone.\n\n\n"; return 0; }