Hi,
I'm writing a code that takes a file name from user and opens it if it exist and if it doesn't asks for another file name. What i wrote is this:
#include <iostream>
#include <string.h>
#include <string>
#include <stdlib.h>
using namespace std;
int mani()
{
string input;
cout<<"please enter the file name:"<<'\n';
getline(cin, input);
FILE *log =fopen (input,"r")
if (!log)
printf("can not open the file.\n");
else
break;
// fclose (log);
return 0;
}
But I'm getting these errors. Any suggestion what i need to do?
ReadFileName.cpp:13: error: cannot convert 'std::string' to 'const char*' for argument '1' to 'FILE* fopen(const char*, const char*)'
ReadFileName.cpp:14: error: expected ',' or ';' before 'if'
ReadFileName.cpp:16: error: expected primary-expression before 'else'
ReadFileName.cpp:16: error: expected `;' before 'else'