test.txt :
18 19 20
21 22 23
22 23 24
23 24 25
24 25 26
25 26 27
28 29 30
29 30 31
I want to read in the integers in test.txt as strings then create a vector of 3 ints.
If that makes sense, so the output is a vector looking like:
18 19 20, 21 22 23, 22 23 24, 23 24 25, 24 25 26, 25 26 27, 28 29 30, 29 30 31
Heres my code:
#include "test.txt"
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <vector>
#include <array>
using namespace std;
struct M
{
int x;
int y;
int z;
};
int main(){
ifstream file;
file.open("test.txt");
string value;
M XYZ;
vector<M> Vec;
if (file){
while (getline(file, value)){
XYZ.x = stoi(value);
if (value == " ")
XYZ.y = stoi(value);
if (value == " ")
XYZ.z = stoi(value);
}
Vec.push_back(XYZ);
}
else
cout << "Error openning file." << endl;
for (int i = 0; i < Moves.size(); i++)
cout << Moves[i] << endl;
return 0;
}