I'm a 13 year old who is trying to use vectors in C properly for the first time. Although when I write to that vector, I get thrown an exception (segmentation fault). I think it means I'm writing to a illegal memory address or illegally writing to that address?
#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.