0

Нужно открыть файл и считать из него только строку с латинскими буквами и вывести ее. Не знаю как задать условие, что бы считывалась только эта строка.

Здесь считывается только первая строка и выводится, но не проверяет на условие

#include "stdafx.h"
#include <iostream>
#include <stdio.h> 
#include <fstream> 
#include <regex>

using namespace std;
int main()
{
    setlocale(LC_ALL, "rus");
    regex reg("[^A-Za-z]");
    regex reg2("[^А-яа-я]");
    string s; 
    ifstream file("D:\\WE.txt"); 
    getline(file,s);
    if (regex_search(s, reg))
    {
        cout << s;
    }
    else cout << "no";

    file.close(); 
    system("pause");
    return 0;
}
5

1 ответ 1

0

отвечал уже на этот же вопрос, но отвечу еще раз

#include <iostream>
#include <fstream>

#include <regex>

using namespace std;

int main(){
    regex reg("[^A-Za-z ]");
    ifstream in("F://test.txt");

    string str="";
    while(getline(in, str)){
        if(!regex_search(str,reg))
            cout << str << endl;
        }
    in.close();
    return 0;
}

вот мой вывод и вот мой файлвведите сюда описание изображения

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.