簡體   English   中英

從c中的文件獲取輸入時出錯

[英]getting error in taking input from file in c

我想從c ++文件中獲取輸入。 我正在使用Visual Studio2015。用於從文件中獲取輸入的示例代碼函數是:

#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'未定義。 有什么方法可以代替此功能,以便獲得相同的輸出嗎?

嘗試標題#include“ direct.h”,這可能是為什么...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM