0

so im trying to read a file and get each line of this file and put it in some array, the line i get is of type char and my array is of type string so i dont know if im doing something wrong there, so i try to add that line to my array and when i try to print it shows me this error
cannot pass objects of non-POD type `struct std::string' through `...'; call will abort at runtime

and heres my code

int main(int argc, char *argv[])
{
    FILE * file;
    char line[1024];
    int n = 1024;
    string array[1024];
    file = fopen("./cursos.txt", "r");
    if (file == NULL){
         printf("cant open this file\n");
         system("pause");
         return 0;    
    }
    
for(int i =0;i<1024;i++)
{       
        fgets(line, n, file);                            
        array[i] = line;
       
}
    
   printf("the string line is %c\n", array[3]);
    fclose(file);
    system("PAUSE");
    return EXIT_SUCCESS;
}

the error is shown in the line where i try to print it
printf("the string line is %c\n", array[3]);

plz heeelp

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by th3learner
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.