Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago