>" matches these arguments">
int main()
{
char* NamePointer = new char;
std::cout << "Enter the file you want to edit (MUST BE IN THE PROJECT'S DIRECTORY): ";
std::cin >> &NamePointer;
const char* FileName = NamePointer;
delete &NamePointer;
return 0;
}
This returns me the error in the title:
std::cin >> &NamePointer;
Any ideas? This is probably something simple I'm missing, but when I looked it up I didn't get my answer.
JUST FIXED IT, SORRY FOR BOTHERING! I took out the "&" in "&NamePointer".
Yeah I just found out another way of doing this using c_str(). Sorry!
You should have:
std::cin >> NamePointer;
Also, you are just allocating an memory of one character, probably you meant:
char* NamePointer = new char[MAX_SIZE];
and dellocate it as:
delete []NamePointer;
Note that the, C++ way of doing this is to simply use std::string
which takes care of the problem of buffer overflows you get with using char*
:
std::string Name;
std::cin >> Name;
There's no need for the address of operator here. Simply:
std::cin >> NamePointer;
Some other things I've noticed:
char* NamePointer = new char;
You probably want more space than just one character. A simple start may be a large static allocation:
char NamePointer[1024];
In which case, you omit the delete
statement at the end (which also doesn't use an address of operator, by the way).
&
didn't fix it, It still is broken.Check my answer - Alok Save 2012-04-04 03:30