简体   繁体   English

C ++分号分隔的文件读取

[英]C++ Semicolon separated file reading

I basically have a semicolon separated text file, in that file there are some commands like "A", "P", "R", "S", and the inputs to process according to those commands like names "Ali Aksu, Mithat Köse", like transactions "Process, withdraw". 我基本上有一个用分号分隔的文本文件,该文件中有一些命令,例如“ A”,“ P”,“ R”,“ S”,以及根据这些命令处理的输入,例如名称“ Ali Aksu,MithatKöse” ”,就像交易“处理,提取”。 I have a program which process those inputs without any problems in console (User gives the inputs). 我有一个程序可以处理这些输入,而不会在控制台中出现任何问题(用户可以提供输入)。 But i need to make it getting the inputs from the semicolon separated file. 但是我需要使其从分号分隔的文件中获取输入。 Here is a test for the reading: 这是一个阅读测试:

This is an example input file: 这是一个示例输入文件:

A;Ali;Aksu;N;2;deposit;withdraw
P
A;Mithat;Köse;P;3;deposit;credit;withdraw

This is the output on the console: 这是控制台上的输出:

A/Ali/Aksu/N/2/deposit/withdraw
P
A/Mithat/Köse/P/3/deposit/credit/withdraw

/

1.Problem: It cannot read the special characters like "ö" 2.Problem: Why is that starting with this weird "" character? 1.问题:无法读取特殊字符,例如“ö”。2.问题:为什么从这个奇怪的“”字符开始?

#include <iostream>
#include <fstream>

using namespace std;

int main(){
    setlocale(LC_ALL, "Turkish");
    fstream myfile;
    char *string;

    string = new char[50];
    myfile.open("input_file.txt",ios::in);
    while(!myfile.eof()){
        myfile.getline(string, 49, ';');
        cout << string << "/"; 
    }
    myfile.close();
    cout << endl;
    system("pause");
    return 0;
}

I will assume that the file is in UTF8 format. 我将假定该文件为UTF8格式。 If so then you question is really, how to i read UTF8 files using c++ 如果是这样,那么您的问题确实是,我如何使用C ++读取UTF8文件

here is somebody reading chinese How to read an UTF-8 encoded file containing Chinese characters and output them correctly on console? 这是读中文的人如何读取包含汉字的UTF-8编码文件并在控制台上正确输出? . You should be able to adapt this to your locale 您应该能够适应您的语言环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM