c++ std::cin未处理异常:访问冲突写入位置
C++ std::cin Unhandled exception: Access violation writing location
当我试图使用std::cin
时,我得到了一个访问冲突。我正在使用char*
,它不允许我输入我的数据。
void Input(){
while(true){
char* _input = "";
std::cin >> _input; //Error appears when this is reached..
std::cout << _input;
//Send(_input);
您没有为cin
提供一个缓冲区来存储数据。
operator>>(std::istream&, std::string)
将为正在读取的字符串分配存储,但是您使用的是operator>>(std::istream&, char*)
,它写入调用者提供的缓冲区,并且您没有提供可写缓冲区(字符串文字不可写),因此您得到了访问冲突。
char* _input = ""; // note: it's deprecated; should have been "const char*"
_input
是指向字符串字面值的指针。输入是一种未定义的行为。使用
char _input[SIZE]; // SIZE declared by you to hold the enough characters
或
std::string _input;
试试这个:
char _input[1024];
std::cin >> _input;
std::cout << _input;
或更好:
std::string _input;
std::cin >> _input;
std::cout << _input;
相关文章:
- 写入位置0x0000000C时发生访问冲突
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 0xC0000005:读取位置0xCDCDCDC1时发生访问冲突
- 0xC0000005:读取位置0xCDCDCDCD时发生访问冲突
- 读取类的析构函数中的位置时发生访问冲突
- 在尝试使用CUDA分配内存时,我遇到了访问冲突写入位置错误
- 创建 2D 数组0xCCCCCCCC访问冲突写入位置
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 在 C 代码中调用 Python 函数时第三次出现访问冲突写入位置错误
- 0xC0000005:访问冲突读取位置0x0000000000000008
- 使用动态数组访问冲突写入位置
- C++访问冲突读取位置0xDDDDDDCD当我尝试删除已更新的数组时
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- vc++ 访问冲突读取位置
- C++ - 智能指针 - 访问冲突读取位置0xDDDDDDDD
- C++访问冲突读取位置错误
- 调用隔离后访问冲突执行位置0x0000000000000000:New()