Home > OS >  Why does comapring two vectors throws me an exception?
Why does comapring two vectors throws me an exception?

Time:10-27

Comparing the two vectors in the if statement throws an exception (segmentation fault).

 #include <iostream>
 #include <vector> 
 #include <fstream>
 #include <string>
    
    
        std::vector<std::string>setup_file_contents_vec{};
        std::ifstream setup_file_required_scan( "exposcan.txt" );    
        std::string buffer;
        while(setup_file_required_scan >> buffer) { setup_file_contents_vec.push_back(buffer); }
        std::vector <std::string> user_details_confirmation(3);
        for (int i = 0; i < 4; i  ){ std::cout << " "; }
        std::cout << " Login details 1/3\n\n";
        for (int i = 0; i < 6; i  ){ std::cout << " "; }
        std::cout << "First Name : ";
        std::cin >> user_details_confirmation[0];
        if(user_details_confirmation[0] != setup_file_contents_vec[0]) {/* code */}

CodePudding user response:

Thanks to @IgorTandetnik the issue was that the file was empty.

  • Related