Hi All!!

I am relatively new to C++ programming so please forgive me if my question is very basic or silly. I am trying to read files in C++. It opens text based files properly but doesnt open csv files , though I am saving them in the same directory. It doesnt open the file even if we save the csv file as txt file. Also my program is opening the files that are being saved in the current directory only. If we save the same file in other directory & specify the whole path in program then also it fails to open that file. I dont know wht the problem is. Could you people please help me with this.

It is a bit strange that you can open text files but not csv files. They are essentially both text files, and only the file extensions are different. So give us the code that you are using to open the files. Maybe we can find something more by looking at the code. If you are using file paths, you should use double backslashes like "C:\\temp\\temp.txt".

Hi!! heres the code I am using:-

const int MAX=100;
char str[MAX];
ifstream infile;
infile.open("abc.csv");
// I have also tried giving the full path here
if(!infile)
   cout<<"unable to open file";

{
   infile.getline(str,MAX);
   cout<<endl<<str;
}

When compiled & run, this program opens txt file but is unable to open a csv file.

Please help.

Hey!!!

My program worked. I have been doing a silly mistake. I was saving the excel file with csv extension but not as a text file. Thanks wolfpack! your advice of using double backslash worked & it solved my 2nd problem.

Thankyou guys!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.