how to read csv file ?

hello , anyone tell me why it not open my csv file ,i write code
#include<iostream>
#include<fstream>
#include<cstdlib>

int main()
{
std::ifstream myFile;
myFile.open("data.csv");

if(!myFile.is_open())
{
std::cout<<"error";
}
else
{
while(myFile.good())
{
std::string line;
std::getline(myFile,line,',');
std::cout<<line<<std::endl;
}
}
return 0;

}
compilor print error
It compiles just fine.

Oh, you mean you have a RUN-TIME error.

On the assumption that std::cout<<"error"; is because "file not found" and not something like "permission denied", you need to make sure there is actually a file called data.csv in the current directory.

Typically, you're either
- looking in the wrong place, or at least where you don't expect.
- you have that god-awful M$ "efficiency" known as "hide known extensions" and your file is really called data.csv.txt
Thank you for the reply ,so what i have to do because data.csv file is exist in the same folder
it reads txt file but not csv file
Topic archived. No new replies allowed.