0

我想从 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'未定义。有什么办法可以替换这个函数,让我得到同样的输出?

4

1 回答 1

0

尝试标题#include“direct.h”这可能是为什么......

于 2016-09-17T19:38:52.530 回答