我想从 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/