unabel to resolve identifyer myfile

Could some body please explan why this code dose not work

#include <iostream>
#include <fstream>
using namespace std;

int main()
{

fstream myfile ;

myfile.open (file location) // it is a photo .jpeg and this is the line that is the problem

return 0;
}

All I want it to do is open the specifyed picture

thanks
Last edited on
Please post working code. The problem likely lies in what "file location" is.
my actual code is this it is just a start menu for a game


#include <iostream>
#include <string>
#include "links.h"
#include <fstream>
using namespace std;
string start;
int main()
{
int st = 1;
string start;

loop:

if (st <= 2)
cout << "WELCOME TO YOUR STORY \n A GAME ALL ABOUT YOU" << endl;
cout << "" << endl;
cout << "press s to start or press h for help " << endl;

getline (cin, start);

if (start == "s")
st = st+1;

else if (start == "h")
st = st+2;

else if (start == "a")
st = st+3;

if (st == 2)

profile();

else if (st == 3)

help();

else if (st == 4)

fstream myfile;
myfile.open ("/home/mark/NetBeansProjects/CppApplication_1/android.jpeg");

else if (st <= 2)
{
cout << "try again" << endl;

goto loop;
}
return 0;
}

thanks
And what was the error?
unable to resolve identifyer 'myfile' at this point


fstream myfile;
here -> myfile.open ("/home/mark/NetBeansProjects/CppApplication_1/android.jpeg");
On the line you try to call .open() myfile no longer exists. Your code looks like this:
1
2
3
4
else if(st == 4) {
    fstream myfile;
}
myfile.open(...);

You'll want to include the entire set of statements in braces.

That said, you shouldn't be using goto to create a loop. Use an actual loop instead (for/while).
Topic archived. No new replies allowed.