Home c++ How to skip / jump to the end of the line when...

How to skip / jump to the end of the line when reading the C++ file




There is a file with the text. The program reads all character by character. If found, for example the letter of the English alphabet – you need to go to the next line to be read. how to implement it?
Here is the code snippet:

string s;
char sy;
while (file.get (sy)) // read the file character by character
  s = s + sy;
  if (sy == '.') {
    textStr.push_back (s);
    CheckCorrectInput (str); // function searches for English characters.
    if (eror) {// if the function has found that ...
      GO to the next line

Answer 1, Authority 100%

getline (filename, s) – just what you need


Answer 2

The problem decided. Pulled out of their code.

void MyString :: CheckCorrectInput (string textStr) {
  Try {
    error = true;
    if (textStr.check_symb ()) throw "Invalid characters \ nPlease try again \ n";
      error = false;
  catch (const char * v) {
    COUT & LT; & LT; v & lt; & lt; Endl;
  catch (...) {
    COUT & LT; & LT; "Unplanned exception";
void MyString :: InputFromFile () {
    while (getline (file, s1)) {// read the string from the file
      error = false; // check box to skip the line. Value varies in function CheckCorrectInput
      for (char sy: s1) {// Check each element in row
        if (sy == '\ n') continue; // if the transition to the next. string to do nothing
        s = s + sy; // add to the character string
        if (sy == '.') {// If the dot, then throw this proposal into a vector such as string. It is possible and without it, but it's a small part of my code, so I need it.
          textStr.push_back (s);
          for (string str: textStr) {
            if (error) {break; } // check flag that is sought in CheckCorrectInput. The default value is false
            COUT & LT; & LT; "\ NPredlozhenie №" & lt; & lt; i & lt; & lt; "";
            CheckCorrectInput (str); // find the letters of the English. Language
            I ++;
          textStr.pop_back (); // remove the element from the vector
          s.clear (); // clear line

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions