Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++;Debian 8.1 Jessie中的错误和fopen错误_C++_Linux_G++_Fopen_Errno - Fatal编程技术网

C++ g++;Debian 8.1 Jessie中的错误和fopen错误

C++ g++;Debian 8.1 Jessie中的错误和fopen错误,c++,linux,g++,fopen,errno,C++,Linux,G++,Fopen,Errno,我在Windows8.1、VisualStudio2013 Express中编写了一些代码。现在,我正试图在运行Debian 8.1 Jessie的Beagle Bone Black上传输并运行此代码。这是我第一次使用Linux,所以我遇到了一些问题 #include <iostream> #include <errno.h> #include <stdio.h> using namespace std; int main() { FILE *cf

我在Windows8.1、VisualStudio2013 Express中编写了一些代码。现在,我正试图在运行Debian 8.1 Jessie的Beagle Bone Black上传输并运行此代码。这是我第一次使用Linux,所以我遇到了一些问题

#include <iostream>
#include <errno.h>
#include <stdio.h>

using namespace std;

int main()
{
    FILE *cfPtr;
    errno_t err;

    if ((err = fopen_s(&cfPtr, "objects.txt", "a +")) != 0) // Check if we can reach the file
        cout << "The file 'objects.txt' was not opened.\n";
    else
        fclose(cfPtr);

    return 0;
}
我明白了,*\s的Windows函数,那么我如何解决这个问题和错误呢


谢谢。

正如您所说,fopen_s是Microsoft Windows特定于C标准库的扩展,您需要改用fopen

现在,errno\u t基本上只是一个,所以可以使用int来代替

我建议这样做:

#include <iostream>
#include <stdio.h>

using namespace std; // bad

int main(){
     FILE *cfPtr = fopen("objects.txt", "r");

     if (cfPtr == NULL){
         cout << "The file 'objects.txt' was not opened.\n";
     } else {
         cout << "Success!";
         fclose(cfPtr);
     }
     return 0;
}
#包括
#包括
使用命名空间std;//坏的
int main(){
文件*cfPtr=fopen(“objects.txt”、“r”);
如果(cfPtr==NULL){

正如您所说,fopen_s是Microsoft Windows特定于C标准库的扩展,您需要使用fopen

现在,errno\u t基本上只是一个,所以可以使用int来代替

我建议这样做:

#include <iostream>
#include <stdio.h>

using namespace std; // bad

int main(){
     FILE *cfPtr = fopen("objects.txt", "r");

     if (cfPtr == NULL){
         cout << "The file 'objects.txt' was not opened.\n";
     } else {
         cout << "Success!";
         fclose(cfPtr);
     }
     return 0;
}
#包括
#包括
使用命名空间std;//错误
int main(){
文件*cfPtr=fopen(“objects.txt”、“r”);
如果(cfPtr==NULL){

不能给
g++-std=c++0x source.cpp-o source
a trygive
g++-std=c++0x source.cpp-o source
a tryOh,那东西在c++11中,但主要是因为大猩猩把它放在了那里。哦,那东西在c++11中,但主要是因为大猩猩把它放在了那里。