错误:使用未声明的标识符"缓冲区"C++
error: use of undeclared identifier 'buffer' C++
我在同一行上两次收到此错误,但在不同的位置(同一问题(:
Documents/JoeInstaller.cpp:33:43: error: use of undeclared identifier 'buffer'
memset(buffer, (char)NULL, sizeof(buffer)))
^
Documents/JoeInstaller.cpp:33:16: error: use of undeclared identifier 'buffer'
memset(buffer, (char)NULL, sizeof(buffer)))
这是我到目前为止的代码:
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <stdio.h>
#include <curl/curl.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
float pythonver;
int main(int argc, char* argv[]){
cout << "Press entern::";
if (cin.get() == 'n')
char buffer[1000];
FILE* progOutput;
progOutput = popen("which python3.6", "r");
if (!progOutput) {
cerr<<"npopen failedn";
exit(1);
}
memset(buffer, (char)NULL, sizeof(buffer)))
if (fread(buffer, sizeof(char), sizeof(char) * sizeof(buffer), progOutput) < 0) {
cerr<<"nfread failedn";
exit(1);
}
if (pclose(progOutput) < 0) {
cerr<<"npclose failedn";
exit(1);
}
pythonver << atof(buffer<<endl.c_str());
if (pythonver) {
cout << "Hooray! Now you need to install python3.6 or later from source!";
}
总之,我想做的是获取python的版本。我正在通过 popen 执行此操作并将结果保存到字符串中。执行此操作时会遇到错误。
此行缺少一个大括号:
if (cin.get() == 'n')
因此,分支仅涵盖下一行(请参阅页面末尾的Notes
(,即buffer
声明:
if (cin.get() == 'n')
char buffer[1000];
// buffer is out of scope here
根据您想要的内容,您需要在整个块或其某些部分周围添加大括号,以保持buffer
在使用时保持活动状态。
相关文章:
- C++字符*缓冲区的大小
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 为什么msgrcv()将垃圾字符馈送到缓冲区
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- ostream过载时的缓冲区冲洗
- #ifdef和未声明的标识符
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- Xaudio2在更改缓冲区或循环时弹出声音
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 多线程双缓冲区
- f2、f3、f4标识符未找到
- Android P-9.0.0_r53 Logcat主缓冲区超出定义大小
- 套接字读取后,我在缓冲区中看到意外输入
- std::带有自定义缓冲区的 iostream 不允许我写入
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- OpenGL 16 位模板缓冲区?
- 错误:使用未声明的标识符"缓冲区"C++