how to use strings with loop

thank you
Last edited on
on line 42 you are redefining infile and reopening the file stringassign.txt.

It seems that it would make more sense to move the loop into the main, and send each member of the array to breakoriginalnumber(...).

You can do this using the string variable tele, and by passing by reference. so your breakoriginalnumber(...) function looks like this now:

1
2
3
4
5
6
void breakoriginalnumber (string & areacode, string & exchange, string & extension, string& tele)
{   
    areacode = tele.substr (1,3);
    exchange = tele.substr (6,3);
    extension = tele.substr(10,4);
}


Now that BON now just separates the phone number, you need to loop through each member, send it to BON, and output the value:

1
2
3
4
5
6
7
8
9
10
//...
for(int x = 0; x < n; x++)
{
       breakoriginalnumber (areacode, exchange, extension, lines[x]);

      cout<< "areacode is " <<areacode;
      cout <<"exchange is " << exchange;
      cout<< "extension is " << extension;
}
//... 

Thanks can you explain to me why do I use lines [x] in the function breakoriginalnumber? I thought if you want to use an array, you have to put it in the parameter for void BON. And why is subscript x being used?
Last edited on
Topic archived. No new replies allowed.