【问题标题】:C++ Semicolon separated file readingC++分号分隔文件读取
【发布时间】:2016-02-06 15:43:16
【问题描述】:

我基本上有一个分号分隔的文本文件,在该文件中有一些命令,如“A”、“P”、“R”、“S”,以及根据这些命令处理的输入,如名称“Ali Aksu , Mithat Köse”,就像交易“处理,撤回”。我有一个程序可以在控制台中处理这些输入而没有任何问题(用户提供输入)。但我需要让它从分号分隔的文件中获取输入。这是一个阅读测试:

这是一个示例输入文件:

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

这是控制台的输出:

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

/

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;
}

【问题讨论】:

  • Google for Utf-8 / Unicode 和 CSV

标签: c++


【解决方案1】:

我假设文件是​​ UTF8 格式。如果是这样,那么你的问题是,我如何使用 c++ 读取 UTF8 文件

这里有人读中文How to read an UTF-8 encoded file containing Chinese characters and output them correctly on console?。你应该能够适应你的语言环境

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多