hi i am a beginner and we just started learning about strings. i am supposed to write a program that creates a structure and use a string in structure.Then the string divide in two parts, after division we print both parts separately.I would appreciate some help. thank you
#include <iostream>
#include <string>
struct StringDiv
{
std::string m_front;
std::string m_back;
StringDiv ();
};
int main()
{
StringDiv sD;
}
StringDiv::StringDiv() // let the ctor do all the work;
{
std::cout << "Enter string to be divided: \n";
std::string input;
getline(std::cin, input);
std::cout << "Size of input string is " << input.size() << "\n";
std::size_t demarc;
do
{
std::cout << "Enter demarcation point (<= input size): ";
std::cin >> demarc;
} while ((demarc <= 0) || (demarc >= input.size())); // so that each part is non-empty
m_front = input.substr(0, demarc); // split input string by demarcation point
m_back = input.substr(demarc, input.size()-1);
std::cout << "Front string: " << m_front << "\n";//also check if string.back() == " " and can cout that
std::cout << "Back string: " << m_back << "\n";//also check if string.front() == " " and can cout that
}