So ig my error has something to do with std::vector in the read function? I'm not sure how to do the other fixes you recommended besides converting it to ifstream, which i just tried and didn't work. When i run the program this is what is displayed in the console window:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 30) > this->size() (which is 29)
Process returned 3 (0x3) execution time : 0.434 s
Press any key to continue. |
Split function: while (delimPosition != string::npos) <-- that's my one and only warning, and it's telling me:
C:\STAC CP2- brennan\prog3\Program3\main.cpp|152|warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]| --
my teacher just told us to copy and paste that code from his example program soo that one warning should be fine... i think lol
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
|
void split(const string& s, char delim, vector<string>& tokens)
{
int tokenStart = 0; // Starting position of the next token
// Find the first occurrence of the delimiter.
int delimPosition = s.find(delim);
// While we haven't run out of delimiters...
while (delimPosition != string::npos)
{
// Extract the token.
string tok = s.substr(tokenStart, delimPosition - tokenStart);
// Push the token onto the tokens vector.
tokens.push_back(tok);
// Move delimPosition to the next character position.
delimPosition++;
// Move tokenStart to delimPosition.
tokenStart = delimPosition;
// Find the next occurrence of the delimiter.
auto delimPosition = s.find(delim);
// If no more delimiters, extract the last token.
if (delimPosition == string::npos)
{
// Extract the token.
string tok = s.substr(tokenStart, delimPosition - tokenStart);
// Push the token onto the vector.
tokens.push_back(tok);
}
}
}
|
I just tried using ifstream instead and got the same error.
Full input file:
Player Tm W L GA SA
Jake Allen STL 19 17 121 1277
Frederik Andersen TOR 36 16 162 1958
Craig Anderson OTT 17 27 163 1676
Richard Bachman VAN 0 1 6 29
Jonathan Bernier DET 9 18 98 1025
Jordan Binnington STL 24 5 59 807
Ben Bishop DAL 27 15 87 1323
Mackenzie Blackwood NJD 10 10 55 669
Sergei Bobrovsky CBJ 37 24 153 1756
Landon Bow DAL 0 0 1 19
Kevin Boyle ANA 1 3 10 139
Laurent Brossoit WPG 13 6 49 652
Peter Budaj LAK 0 1 6 33
Jack Campbell LAK 10 14 61 845
Eric Comrie WPG 0 1 5 28
Mike Condon OTT 0 2 8 40
Pheonix Copley WSH 16 7 74 776
Corey Crawford CHI 14 18 108 1176
Joey Daccord OTT 0 1 5 40
Scott Darling CAR 2 4 27 233
Collin Delia CHI 6 4 50 545
Aaron Dell SJS 10 8 70 613
Thatcher Demko VAN 4 3 25 288
Casey DeSmith PIT 15 11 89 1060
Michael Dipietro VAN 0 1 7 24
Louis Domingue TBL 21 5 75 812
Devan Dubnyk MIN 31 28 163 1877
Brian Elliott PHI 11 11 69 741
Marc-Andre Fleury VEG 35 21 152 1745
Pavel Francouz COL 0 2 2 35
Kaden Fulcher DET 0 0 2 11
Alexandar Georgiev NYR 14 13 91 1057
Christopher Gibson NYI 0 0 1 17
John Gibson ANA 26 22 153 1838
Thomas Greiss NYI 23 14 87 1185
Philipp Grubauer COL 18 9 89 1071
Jaroslav Halak BOS 22 11 90 1158
Carter Hart PHI 16 13 81 976
Connor Hellebuyck WPG 34 23 179 2051
Adin Hill ARI 7 5 32 322
Marcus Hogberg OTT 0 2 14 121
Braden Holtby WSH 32 19 160 1795
Jimmy Howard DET 23 22 156 1709
Michael Hutchinson TOT 3 4 27 239
Carter Hutton BUF 18 25 142 1541
Tristan Jarry PIT 0 1 7 62
Chad Johnson TOT 2 11 49 406
Martin Jones SJS 36 19 176 1699
Anton Khudobin DAL 16 17 95 1232
Keith Kinkaid NJD 15 18 129 1188
Joonas Korpisalo CBJ 10 7 67 651
Mikko Koskinen EDM 25 21 146 1551
Darcy Kuemper ARI 27 20 126 1676
Maxime Lagace VEG 0 1 4 31
Robin Lehner NYI 25 13 93 1323
Charlie Lindgren MTL 1 0 5 49
Henrik Lundqvist NYR 18 23 158 1699
Roberto Luongo FLA 18 16 122 1205
Alex Lyon PHI 0 1 6 31
Jacob Markstrom VAN 28 23 166 1896
Curtis McElhinney CAR 20 11 85 968
Mike McKenna TOT 1 5 34 316
Ryan Miller ANA 8 7 51 578
Hunter Miska ARI 0 0 1 9
Sam Montembeault FLA 4 3 30 282
Petr Mrazek CAR 23 14 95 1104
Matt Murray PIT 29 14 129 1594
Alex Nedeljkovic CAR 1 0 2 26
Michal Neuvirth PHI 1 4 26 184
Antti Niemi MTL 8 6 61 539
Anders Nilsson TOT 14 19 101 1098
Eddie Pasquale TBL 2 1 12 102
Calvin Petersen LAK 5 4 27 355
Calvin Pickard TOT 4 6 48 384
Carey Price MTL 35 24 161 1952
Jonathan Quick LAK 16 23 149 1329
Antti Raanta ARI 5 6 33 351
Tuukka Rask BOS 27 13 109 1245
James Reimer FLA 13 12 93 929
Pekka Rinne NSH 30 19 130 1581
David Rittich CGY 27 9 109 1228
Juuse Saros NSH 17 10 74 870
Cory Schneider NJD 6 13 70 718
Mike Smith CGY 23 16 109 1069
Garret Sparks TOR 8 9 58 592
Alex Stalock MIN 6 8 53 525
Anthony Stolarz TOT 4 5 50 503
Malcolm Subban VEG 8 10 60 612
Cam Talbot TOT 11 17 108 997
Linus Ullmark BUF 15 14 109 1146
Semyon Varlamov COL 20 19 136 1496
Andrei Vasilevskiy TBL 39 10 128 1713
Cam Ward CHI 16 12 115 1113