# opencsv **Repository Path**: linyouhappy/opencsv ## Basic Information - **Project Name**: opencsv - **Description**: 跨平台多线程设计! 使用C++分析大数据的时候,数据按CSV格式导出,可以用Excel分析数据。 OpenCSV非常简单易用。 **OpenLinyou项目设计跨平台服务器框架,在VS或者XCode上写代码,无需任何改动就可以编译运行在Linux上,甚至是安卓和iOS.** OpenLinyou:https://github.com/openlinyou - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2023-03-05 - **Last Updated**: 2025-03-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # opencsv Cross-platform multi-threaded design! Read and write csv file. **The OpenLinyou project designs a cross-platform server framework. Write code in VS or XCode and run it on Linux without any changes, even on Android and iOS.** OpenLinyou:https://github.com/openlinyou ## Cross-platform support Designed for cross-platforms such as Windows and Linux. ## Compilation and execution Please install the cmake tool and use it to build the project. It can be compiled and run on VS or Xcode. Source code: https://github.com/openlinyou/opencsv ``` # Clone the project git clone https://github.com/openlinyou/openthread cd ./opencsv # Create a build project directory mkdir build cd build # If it is win32, opencsv.sln will appear in this directory. Click it to start VS for coding and debugging. cmake .. make ./test ``` ## All source files + src/opencsv.h + src/opencsv.cpp ## Test Demo ```C++ #include #include "opencsv.h" int main() { std::string buffer1; std::string buffer2; //make csv { OpenCSV csv = { "ID", "name", "salary" }; csv = { "1", "Jack", "100000" }; csv = { "2", "Tom", "80000" }; csv = { std::to_string(3), "Lucy", "50000" }; csv >> buffer1; } buffer2 = "ID,name,salary\n" "1,Jack,100000\n" "2,Tom,80000\n" "3,Lucy,50000\n"; assert(buffer1 == buffer2); //parse csv { OpenCSV csv; csv << buffer2; buffer1 = "ID,name,salary\n"; for (size_t i = 1; i < csv.size(); ++i) { auto& line = csv[i]; buffer1.append(line["ID"] + "," + line["name"] + "," + line["salary"] + "\n"); } } assert(buffer1 == buffer2); std::string filePath = "./test.csv"; //make csv file { OpenCSV csv; csv << buffer2; assert(csv[0][0] == "ID"); assert(csv[0][2] == "salary"); csv[1]["salary"] = std::to_string(10000); csv[2]["salary"] = "8000"; csv[3]["salary"] = "5000"; csv >> filePath; } buffer2 = "ID,name,salary\n" "1,Jack,10000\n" "2,Tom,8000\n" "3,Lucy,5000\n"; //read csv file { OpenCSV csv; csv << filePath; buffer1.clear(); csv >> buffer1; } assert(buffer1 == buffer2); return 0; } ``` ## Environment Windows、linux etc. Cross-platform design ## Source file list . src/opencsv.h . src/opencsv.cpp ## Build and run ``` cd ./opencsv mkdir build cd build cmake .. make ./test ```