CLion работает неожиданным образом - PullRequest
0 голосов
/ 02 апреля 2020

Я работаю над своим университетским заданием, в котором я должен считать слова в файле и количество их использования. У меня есть следующий код, который прекрасно работает, если вы скомпилируете его с g ++ вручную:

#include <iostream>
#include <ostream>
#include <fstream>
#include <map>
#include <boost/locale.hpp>

inline auto read_file_into_memory(const std::string &file_name) {

    std::ifstream raw_file(file_name, std::ios::binary);
    auto buffer = static_cast<std::ostringstream&>(
            std::ostringstream{} << raw_file.rdbuf()).str();

    return buffer;
}


inline auto split_and_count( const std::string &file_content, std::map<std::string, int>* dictionary ){

    std::string word = "";

    for (auto &symbol: file_content){

        if ( isalpha(symbol) || symbol == '-' ){
            word += tolower(symbol);
        }

        else if ( (ispunct(symbol) || isspace(symbol) ) && word.size() > 0 ){

            if ( (*dictionary).find(word) == (*dictionary).end() ){
                (*dictionary).insert( {word, 1} );
            }
            else{
                (*dictionary)[word] += 1;
            }

            word = "";
        }
    }
}

inline auto print_results( const std::map<std::string, int> &dictionary ){

    for (std::pair<std::string, int> element : dictionary) {
        std::string word = element.first;
        int count = element.second;
        std::cout << word << " :: " << count << std::endl;
    }

}


int main() {
    std::map<std::string, int> dictionary;
    std::string current_file = "sample.txt";

    auto buffer = read_file_into_memory(current_file);

//    buffer = boost::locale::normalize(buffer, boost::locale::norm_nfd);

    split_and_count(buffer, &dictionary);
    print_results(dictionary);

    return 0;
}

Но, когда я пытаюсь запустить его на Clion, я не получаю ответ и сообщение: Процесс завершен с выходом код 0

Я использую следующий файл cmakelists.txt:

cmake_minimum_required(VERSION 3.15)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

add_executable(counting_words1 main.cpp)

Пожалуйста, кто-нибудь может объяснить это поведение CLion?

...