2022-12-28 09:50:44 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <nowide/args.hpp>
|
|
|
|
#include <nowide/fstream.hpp>
|
|
|
|
#include <nowide/iostream.hpp>
|
|
|
|
#include <whereami++.hpp>
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void check_file(T& file) {
|
|
|
|
if (not file) {
|
|
|
|
nowide::cerr << "Can't open file" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::size_t total_lines = 0;
|
|
|
|
while (file) {
|
|
|
|
if(file.get() == '\n') {
|
|
|
|
total_lines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nowide::cout << "File has " << total_lines << " lines" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
std::string executable_folder = whereami::executable_dir();
|
|
|
|
nowide::cout << "whereami::executable_dir() = " << executable_folder << std::endl;
|
2022-12-28 10:15:22 +01:00
|
|
|
|
|
|
|
auto direct_u8path = std::filesystem::u8path(whereami::executable_dir());
|
|
|
|
nowide::cout << "u8path{whereami::executable_dir()} = " << direct_u8path << std::endl;
|
2022-12-28 09:50:44 +01:00
|
|
|
|
|
|
|
auto u8string = std::u8string(executable_folder.begin(), executable_folder.end());
|
2022-12-28 10:15:22 +01:00
|
|
|
nowide::cout << "std::u8string{_} = " << reinterpret_cast<const char*>(u8string.c_str()) << std::endl;
|
2022-12-28 09:50:44 +01:00
|
|
|
|
|
|
|
std::filesystem::path u8path{u8string};
|
|
|
|
nowide::cout << "std::filesystem::path{_} = " << u8path << std::endl;
|
|
|
|
|
2022-12-28 10:15:22 +01:00
|
|
|
nowide::cout << "nowide::ifstream{_.string()} : " << std::endl;
|
|
|
|
nowide::ifstream file_from_path((u8path / "test_file.txt").string());
|
2022-12-28 09:50:44 +01:00
|
|
|
check_file(file_from_path);
|
2022-12-28 10:15:22 +01:00
|
|
|
|
|
|
|
nowide::cout << "nowide::ifstream{direct_u8path.string()} : " << std::endl;
|
|
|
|
nowide::ifstream file_from_path2((direct_u8path / "test_file.txt").string());
|
|
|
|
check_file(file_from_path2);
|
2022-12-28 09:50:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|