本文介绍了使用fopen打开文件,在Windows上给出绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个程序计数一个文件的行数,当我尝试传递绝对路径到fopen函数,只是告诉我,没有找到,这里是我的代码: #include< iostream>
#include< stdio.h>
#include< stdlib.h>
using namespace std;
int main(int argc,char * argv [])
{
int i = 0;
char array [100];
char caracteres [100];
FILE * archivo;
archivo = fopen(C:\Documents和Settings \juegos psps.txt,r);
if(archivo == NULL){cout<<Dont Work;}
while(feof(archivo)== 0)
{
fgets(caracteres,100 ,archivo);
i ++;
}
cout<< 行数:<一世 ;
return 0;
}
如何将绝对路径传递给我的程序, ?
解决方案
使用双斜杠:
C:\\Documents和Settings\\juegos psps.txt
I'm trying to make a program that counts the number of lines of a file, when I try to pass the absolute path to the fopen function, is simply tells me that is not found, here is my code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
int i=0;
char array[100];
char caracteres[100];
FILE *archivo;
archivo = fopen("C:\Documents and Settings\juegos psps.txt","r");
if (archivo == NULL){cout<<"Dont Work";}
while (feof(archivo) == 0)
{
fgets(caracteres,100,archivo);
i++;
}
cout << "Number of lines:" << i ;
return 0;
}
How should I pass the absolute path to my program so you can open the file?
解决方案
Use double slashes:
"C:\\Documents and Settings\\juegos psps.txt"
这篇关于使用fopen打开文件,在Windows上给出绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!