简体   繁体   中英

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". 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?

#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. If so then you question is really, how to i read UTF8 files using c++

here is somebody reading chinese How to read an UTF-8 encoded file containing Chinese characters and output them correctly on console? . You should be able to adapt this to your locale

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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