Home > Article > Backend Development > How can I read and manipulate CSV file data in C ?
How to Read and Manipulate CSV File Data in C
Understanding the techniques to read and manipulate CSV (Comma-Separated Values) file data in C is crucial. To delve into this topic, let's consider the following question:
Question:
How can I read and manipulate CSV file data in C ?
Answer:
Without additional context, a basic approach involves using the following libraries:
#include <iostream> #include <sstream> #include <fstream> #include <string>
Here's an example code snippet:
int main() { std::ifstream data("plop.csv"); std::string line; while (std::getline(data, line)) { std::stringstream lineStream(line); std::string cell; while (std::getline(lineStream, cell, ',')) { // Logic to manipulate the cell } } return 0; }
This code opens the CSV file named "plop.csv" and iterates over each line. For each line, it splits the cells using the comma (",") delimiter. This allows you to access and manipulate the individual cells within the CSV file.
The above is the detailed content of How can I read and manipulate CSV file data in C ?. For more information, please follow other related articles on the PHP Chinese website!