What type of error are you getting? Because from what I can tell, on line 1, you have string type accidentally capitalized to "String". Unless this is a custom class that you made for the purposes of your program, there's nothing syntactically wrong with your code.
if (getstock.fail())
{
cerr << "sorry unable to display stock";
getstock.close();
}
else
{
getstock>> itemstock;
cout << "the stock for "<< itemname <<"is"<< itemstock;
getstock.close();
}
}
</code>
this function is part of a class in which itemstock is already defined.i am always getting the error of "sorry unable to dislplay stock".
Might just be a hunch but it may have something to do with the slashes in your "item\\". I don't think the compiler (whichever one you use) should read them as null or empty characters, but I'm no expert on compilers.
Also there maybe be an issue with order of operation, so I would do ("item" + itemname) if it allows that.
it may have something to do with the slashes in your "item\\".
Double slash is escape character (slash) + escaped character (slash) together they will embed a single \ into string (as slash is a special symbol in strings, you canot use it directly)
Do you really have a file with that name? Can it be open already by another stream?