0
int main(){
	// I have an error in the next line
	read_file("F:/2nd year_2/Data structure 2/books/lecture-26.pdf");
	return 0;
}
string read_file(char* address){
	 string line;
	
  ifstream myfile (address);
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }
	return NULL;
}

this program have an error and I think the problem is the file path
so how can I write it correctly

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by eman 22
0

For starters, I would suggest never using spaces in a file name :)

If you insist on doing so, I think Windows likes backslashes instead of forward slashes - I don't if c++ cares about this.

Also, you may need to "escape" the space with a backslash:
read_file("F:/2nd\ year_2/Data structure 2/books/lecture-26.pdf");

0

I removed the spaces from the address and change the foreword slash with black slash (single and double) but I'm still having the same problem
and that's the error
identifier not found

0

Please include the entire compiler output. Which identifier is not found? My guess would be read_file, since you didn't declare it before main.

0

yeah, you are right.
this error occurred because I declared a red_file method before the main method

Thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.