Task
Implement the two functions which proceed to exchange between string and cstring.
(1) std::string change1(const char* cstr);
Convert a string of the cstring type to one belonging to the string type.
(2) void change2(std::string str, char* cstr);
Convert a string of the string type to one belonging to the cstring type.
main.cpp
#include <cstdio>
#include <iostream>
#include "exchange.h"
std::string str;
char cstr[100];
int main() {
std::cin >> str;
change2(str, cstr);
puts(cstr);
scanf("%s", cstr);
std::cout << change1(cstr) << std::endl;
return 0;
}
exchange.h*
#include <cstring>
std::string change1(const char* cstr){
std::string str_;
str_ = cstr;
return str_;
}
void change2(std::string str, char* cstr){
strcpy(cstr,str.c_str());
}