Yes, it's correct. It can also be simplified, for example:
#include<fstream>
#include<string>
using namespace std;
void writeValue(const char* file, int value){
ofstream f(file);
if (f)
f<<value;
}
int main()
{
string s = "text";
writeValue(s.c_str(), 12);
}
It may be more convenient in C++, to take const char* rather then char *, because string can readily be converted to const char *.