Hello all I am trying to input a text file into an array. The problem is the text file has ten rows and three columns that I need to work with. I am able to input the file into the array but don't know how to call on each item of the text file. The file name is "Weapons.txt" and here is what it looks like:
#include<string>
#include<iostream>
#include<sstream>
#include<vector>
int main()
{
// example line
std::string line("Pencil 1 42");
// things to assign to (with some defaults)
std::string name = "";
int hands = 1;
int attackpower = 1;
std::istringstream ss(line);
std::vector<std::string> vec;
do
{
std::string sub;
ss >> sub;
vec.push_back(sub);
} while (ss);
name = vec.at(0);
hands = atoi(vec.at(1).c_str());
attackpower = atoi(vec.at(2).c_str());
return 0;
}
it's not very elegant, but i'm supposed to be doing my own work too :)