Question
Convert string to char array in C++ strcpy() function TO SIMPLE COPY EXAMPLE 1 using strcpy() #include #include using namespace std; // driver code int
Convert string to char array in C++ strcpy() function TO SIMPLE COPY EXAMPLE 1 using strcpy()
#include
#include
using namespace std;
// driver code
int main()
{
// assigning value to string s
string s = "geeksforgeeks";
int n = s.length();
// declaring character array
char char_array[n + 1];
// copying the contents of the
// string to char array
strcpy(char_array, s.c_str());
for (int i = 0; i < n; i++)
cout << char_array[i];
return 0;
} example 2: dont use strcpy()
#include
#include
using namespace std;
// driver code
int main()
{
// assigning value to string s
string s("geeksforgeeks");
// declaring character array : p
char p[s.length()];
int i;
for (i = 0; i < sizeof(p); i++) {
p[i] = s[i];
cout << p[i];
}
return 0;
} ------------------------------now give me some example about using strcmp and without using strcmp()------------------- ------------------------------please do both strcmp and without strcmp() way. So I Can understand.------------------------- -------------------------------Learning about operator---------------------------------- example I have a class
class MyString { char* charArr; int length; class Err {};
bool operator<=( const MyString str ) const { //code here make sure do both way using strcmp and without using strcmp() return; } P/S you can using another example if you want to but please do something I can understand about operator like <= => == < >. thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started