1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <stringstream>
#include <tuple>
#include <iostream>
typedef std::tuple<std::string,int,int,int> mytuple;
int main(int argc, char** argv)
{
std::vector<mytuple> bowl;
std::ifstream infile("c:\\c++data\\bowlers.txt");///assuming the formt is: string,int,int,int
if(infile)
{
std::string temp{},data{};
int var1{},var2{},var{};
std::stringstream s_temp;
for(int i = 0; i<10; i++)
{
s_temp.str(""); s_temp.clear();
std::getline(infile,temp,'\n');///edited
s_temp<<temp;
s_temp>>data>>var1>>var2>>var3;
auto index = data.find_first_of('\r');
if(index != std::string::npos)
data.erase(index,2);
bowl.push_back(std::make_tuple(data,var1,var2,var3));
}
}
else
{
std::cout<<"cannot open file.";
std::cout<<"This program will terminate.";
}
return 0;
}
|