Organize a structure and divide a string in two parts

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
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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
}
Topic archived. No new replies allowed.