I am trying to create a program that reads what is in a text file and then swap places between two elements in the vector.
The text file has this order: NAME, SURNAME, REGISTRATION, _NUMBER AND CITY_ADRESS.
The list is about 100 people. I wonder if there is a way to not include the whole line and end it in a space.
Here is how my code looks like!
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> line;
string information;
ifstream myfile ("Namn.txt");
if (myfile.is_open()) {
while (getline(myfile, information)) {
line.push_back (information);
}
myfile.close();
}else cout << "Filen gick inte att öppna!";
for (unsigned int i = 0; i < line.size(); i++) {
cout << line[i] << endl;
}
return 0;
}