i have this problem- since i need to get my input from a "*.in" file using ifsream.,
is there's an easy way to get input for example-
this is input.in
2
3
wallmart city, cotton city, violete city
3 2 4
2
big mack, mcdonalds
3
i need to get
the first line as # of cases
second line as # of towns
and i need the town to be placed in a variable such that town[0]= wallmart city
town[1]=cotton city town[2] = violete city
and continue to fetch the last line
usingnamespace;
int main()
{
ifstream input;
input.open("d.in");
int num, way, towns; string town,t[10];
input>>num;//as # of cases;
for(int x=0;x<num;x++)
{
input>>towns;//# of towns
getline(cin,town);getline(cin,town); //need to double for pointer to be on the right line
for(int y=0;y<towns;y++)
{
t[y]=town.substr(0,town.find(';'));
town=town.substr(t[y].length()-1,town.length()-1);
cout<<t[y]<<endl;
}
for(int z=0;z<towns-1;z++)//this loop to get the roads
{
input>>way;
}
cout<<endl;
}
input.close();
return 0;
}
actually i already started like this one and still have errors, might as well suggest an easier way