S
S
StoneCraft2017-10-04 23:20:37
Programming
StoneCraft, 2017-10-04 23:20:37

How to make and output a slice of a string (String) C/C++?

I am writing a program that reads text and prints sentences line by line.
How to slice text from NumberArrayString th to i th element ?

int NumberArrayString = 0;
  int NumberString = 0;
  std::string text = {};
  getline(std::cin, text);
  printf("%d", text.size());
  for (int i = 0; i < (text.size()); i++)
  {
    if ((text[i] == '.') || (text[i] == '!') || (text[i] == '?'))
    {
      NumberString++;
      std::cout << NumberString << "-я строка: " << ???????????????????? << std::endl;
      NumberArrayString = i;
                }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2017-10-05
@StownCraft

one.

std::cout << text.substr(начало, длина) << std::endl;

Since we have a training text in front of us, I will not prompt further. At random, find out what will be the beginning and what will be the length.
2. Is it okay that if the line does not end with a dot, the last "undersentence" will not be displayed? Maybe that's true, but if the task is to split the text into tabs or commas, you need to throw out what's left after the loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question