c - 从c中的文件获取输入时出错

标签 c visual-studio file unistd.h

我想从 C++ 文件中获取输入。我正在使用 Visual studio 2015。我从文件获取输入的示例代码函数是:

#define INPUT_FILE_NAME "input.txt"
#define V 15
int total number=0;   
double px[V];
double py[V];      
void fileInput()
{
    FILE *fp;
    char cwd[1024];
    if (getcwd(cwd, sizeof(cwd)) == NULL)   //Directory not found
    {
        perror("getcwd() error - Current directory not found !!");
        exit(0);
    }
    strcat(cwd, "\\");
    strcat(cwd, INPUT_FILE_NAME);
    fp = fopen(cwd, "r");

    int i = 0;
    fscanf(fp, "%d", &start);
    while (fscanf(fp, "%lf", &px[i]) != EOF)
    {
        fscanf(fp, "%lf", &py[i]);
        i++;
        total_number++;
    }
}

我的输入文件格式如下:

2
0 1
2 1

但是当我编译时,我收到一个错误,例如:标识符“getcwd”未定义。有什么方法可以替换这个函数,以便我可以获得相同的输出吗?

最佳答案

尝试 header #include“direct.h”,这可能就是原因......

关于c - 从c中的文件获取输入时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39550792/

相关文章:

c# - 如何从 C# 过渡到 Python?

c++ - 从文件读取时无法使用 getline

file - Windows 2008 R2 - 内核(系统进程 PID=4)正在锁定文件和文件夹

iphone - 使用 Objective-C 以编程方式读取文本文件

c - 从客户端到服务器程序的 I/O 通信读写

c - 使用队列的层序二叉树遍历

linux - 如何在 Visual Code 中的集成终端之间切换?

.net - 调试 Visual Studio 2017 扩展未找到程序集

c - sizeof(arr+1) 输出错误?

C图。无法将边添加到邻接表中