I may be pretty proficient in html but i am a newbie to c++. I am trying to create a program that lets me write basic html webpages.
i want to be able to write to my website by calling file so i decided write:
ofstream file;
file.open ("website.html");
at the top so it could be used globally. The problem is here that on line 6 it gives me an error saying
error: 'file' does not name a type|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
if someone could help me fix my problem or find a way that i can use file with all my functions alternatively that would be greatly appreciated
You can't call statements outside of a function. However, you do have a couple of options. Either you could call open in the first line of main, or you could use its constructor:
std::ofstream file ("website.html");
Note that you should try to avoid global variables when possible. You also don't need to explicitly call file.close, either (the destructor will do that for you).