Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

c++ - Open file with fopen, given absolute path on Windows

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 Settingsjuegos 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use double slashes:

"C:\Documents and Settings\juegos psps.txt"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...