Erorr:无操作符“>>>匹配这些参数 [英] Erorr: no operator ">>" 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!我拿出了&在& NamePointer中。
是的,我刚刚发现了另一种方法使用c_str()。很抱歉!
Yeah I just found out another way of doing this using c_str(). Sorry!
推荐答案
您应该有:
std::cin >> NamePointer;
此外,你只是分配一个字符的内存,可能你的意思是:
Also, you are just allocating an memory of one character, probably you meant:
char* NamePointer = new char[MAX_SIZE];
并将其分配为:
delete []NamePointer;
/www.cplusplus.com/reference/string/string/rel =nofollow> std :: string
来处理缓冲区溢出问题你可以使用 char *
:
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;
这篇关于Erorr:无操作符“>>>匹配这些参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!