相关疑难解决方法(0)

C fopen vs open

您是否有任何理由(语法除外)

FILE *fdopen(int fd, const char *mode);
Run Code Online (Sandbox Code Playgroud)

要么

FILE *fopen(const char *path, const char *mode);
Run Code Online (Sandbox Code Playgroud)

代替

int open(const char *pathname, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)

在Linux环境中使用C时?

c unix linux file-io fopen

201
推荐指数
8
解决办法
16万
查看次数

Visual Studio警告C4996

我收到了以下警告

warning C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files\microsoft visual studio 10.0\vc\include\memory 348

我似乎无法找到任何有助于打击此警告的信息.通过查看输出,这个警告似乎与Boost.Signals2和auto_buffer有关.

这样可以安全忽略,还是可以以某种方式将其删除?

c++ warnings

34
推荐指数
1
解决办法
3万
查看次数

为什么我不能使用fopen?

在上一个问题的模型中,我询问了所谓的安全库折旧,我发现自己同样对于为什么fopen()应该被弃用感到困惑.

该函数接受两个C字符串,并返回FILE*ptr,或者在失败时返回NULL.线程安全问题/字符串溢出问题在哪里?或者是别的什么?

提前致谢

c c++ deprecated tr24731

24
推荐指数
3
解决办法
2万
查看次数

得到错误"fopen":此函数或变量可能不安全.在比赛时

编译时我收到此错误:

'fopen': This function or variable may be unsafe. 
Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
Run Code Online (Sandbox Code Playgroud)

我是C++的新手并且打开CV,因此请帮我摆脱这个错误.

谢谢

void _setDestination(const char* name)
{
    if (name==NULL) {
        stream = stdout;
    }
    else {
        stream = fopen(name,"w");
        if (stream == NULL) {
            stream = stdout;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ fopen opencv

22
推荐指数
2
解决办法
10万
查看次数

有没有办法在GCC中使用fopen_s()或者至少创建一个#define?

MSVC编译器说不fopen()推荐使用,并建议使用fopen_s().

有什么方法可以使用fopen_s()并且仍然可移植吗?

#define什么想法?

c gcc fopen visual-c++

14
推荐指数
3
解决办法
2万
查看次数

MS strncpy_s的替代品

Microsoft安全增强功能(例如strncpy_s或)有哪些替代方法_itoa_s?尽管在MS环境中进行开发,但目标是编写可以轻松移植到其他平台的代码。

c++ visual-c++

5
推荐指数
1
解决办法
5672
查看次数

C4996,fopen弃用:为什么?(不:如何压制)

什么是不安全的,哪个fopen更安全fopen_s

如何以安全的方式使用fopen(如果可能的话)?

(我不想知道如何抑制警告 - 有足够的stackoverflow文章来回答这个问题)

编辑:问题被关闭为"基于意见"(即使只有一个答案,我没有看到太多的意见).我会尝试改写一下:如果有人能够展示微软(不赞成使用该功能)的文档如何/在哪里找到它,这将解释为什么它被弃用会更好.

c fopen tr24731 visual-studio c11

3
推荐指数
1
解决办法
303
查看次数

错误:未在此范围内声明'fileno'

我在Windows 8上运行Cygwin,试图编译我想要mod的游戏的源代码.不幸的是,我在构建涉及fileno函数时遇到了一些错误.做了一些谷歌搜索似乎问题可能与c ++ 11支持有关(我不确定这意味着什么).人们发现的大多数解决方案都涉及在编译时添加一些选项,如-std = c ++ 0x或-std = c ++ 11,但是我尝试将选项添加到makefile中是不成功的,我不知道如果那是什么导致问题无论如何.我将包含抛出错误的代码片段和makefile的链接,因为它非常大.你能给我的任何建议都会很棒.

抛出错误的代码:

    time_t file_modtime(FILE *f)
    {
        struct stat filestat;
        if (fstat(fileno(f), &filestat))
            return 0;

        return filestat.st_mtime;
    }
Run Code Online (Sandbox Code Playgroud)

链接到Makefile

它正在github上托管

编辑:在得到一些建议后,我在makefile周围找到并找到了五个使用-std选项的实例,玩它们并没有改变任何东西.我的Cygwin配置有问题吗?我在我正在构建的游戏的安装指南中安装了我被告知需要的软件包.

c++ makefile c++11

1
推荐指数
1
解决办法
5375
查看次数

C - Sprintf的变量参数?

我有一个功能;

void foo(const char* format, ...)
{
    char buffer[1080];

    // Supposed way to handle C Variable Arguments?
    va_list argptr;
    va_start(argptr, format);
    sprintf(buffer, format, argptr);
    va_end(argptr);

    printf_s("%s.\n", buffer);
}

int main()
{
    int val = 53;
    foo("%d", val);
}
Run Code Online (Sandbox Code Playgroud)

每次运行时,我都会得到每次运行时都会发生变化的大量数字.12253360, 5306452等我不明白为什么.

这是我的sprintf电话,还是我正在做的事情va_list argptr;?我buffer太大了吗?

谢谢.

c variadic-functions

1
推荐指数
1
解决办法
937
查看次数

OpenCV:LINK:致命错误LNK1104:无法打开文件'opencv_haartraining_engined.lib'

我是OpenCV的新手,我尝试了一些故障排除,试图让我的标题编译但继续遇到链接器错误.

这是我想要运行的代码:

//Visual Studio
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>

//LabView
//#include <NIVision.h>

//Opencv 
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

1>------ Rebuild All started: Project: Veni_Main, Configuration: Debug Win32 ------
1>  stdafx.cpp
1>  Veni_Main.cpp
1>c:\opencv\build\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen' …
Run Code Online (Sandbox Code Playgroud)

opencv linker-errors

0
推荐指数
1
解决办法
1万
查看次数