C++ 我想要一些关于字符串函数的帮助

C++ 我想要一些关于字符串函数的帮助,c++,variable-assignment,C++,Variable Assignment,我只能在本练习中使用字符串对象和字符串函数。当我试图在循环中放置“over”时,我在第二个if中看到与第一个if中相同的条件。你在第二个之前忘了什么吗如果,可能是hey=hey.substr(pos);pos=hey.find(“”) 在同一秒的正文中,如果未使用计算的空白。 也许一定有失败者,而不是失败者 @巴尔马给了你一个有用的建议。。。。如果代码段不是Javascript/HTML/CSS,请不要过度使用。文件中有什么?请提供可验证的示例。问题显然在于使用hey.find()解析文件行的代

我只能在本练习中使用字符串对象和字符串函数。当我试图在循环中放置“over”时,我在第二个
if
中看到与第一个
if
中相同的条件。你在第二个
之前忘了什么吗如果
,可能是
hey=hey.substr(pos);pos=hey.find(“”)

在同一秒
的正文中,如果
未使用计算的
空白
。 也许一定有失败者,而不是失败者


@巴尔马给了你一个有用的建议。

。。。如果代码段不是Javascript/HTML/CSS,请不要过度使用。文件中有什么?请提供可验证的示例。问题显然在于使用
hey.find()
解析文件行的代码。显示一个行的示例,我们可能能够找出您做错了什么。cout
行很好,您只是在变量中得到了错误的值。
cout << winner << " over " << loser << " " << winnerscore << " " << loserscore << endl;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>

using namespace std;

int main(){

ifstream fin;
string winner, winnerscore, loser, loserscore, hey, file;
size_t pos, blank, blank2;

fin.open("C:\\Users\\leewi\\Desktop\\Computer Programs & Projects\\C++\\BentleyCIS22B\\Ex5\\Ex5.txt");

if (!fin)
{
    cout << "Can't Open File." << endl;
    exit(0);
}
while(!fin.eof()){
    getline(fin, hey);
    pos = hey.find(' ');
    winner = hey.substr(0, pos);
    if(isalpha(hey[pos+1])){
        blank = hey.find(' ');
        winner += hey.substr(pos, blank);
    }
    else if(isdigit(hey[pos+1]))
    {
        blank = hey.find(',');
        winnerscore = hey.substr(pos, blank);
    }
    if(isalpha(hey[pos+1])){
        blank = hey.find(' ');
        loser += hey.substr(pos, hey.length());
    }
    else if(isdigit(hey[pos+1]))
    {
        loserscore = hey.substr(pos, hey.length());
    }

    cout << winner << " over " << loser << " " << winnerscore << " to " << loserscore << endl;

}
fin.close();
    return 0;
}
Cincinnati over   27, Buffalo  to  27, Buffalo 24
Detroit over   31, Cleve to  31, Cleveland 17
Kansas City  over  City 24, Oakland 7  31, Cleve to  31, Cleveland 17
Carolina over  City 24, Oakland 7  35, Minnes to  35, Minnesota 10
Pittsburgh over  City 24, Oakland 7  19, NY Jets  to  19, NY Jets 6
Philadelphia over  City 24, Oakland 7  31, Tampa Bay  to  31, Tampa Bay 20
Green Bay  over  City 24, Oakland 7 Bay 19, Baltimore 17  31, Tampa Bay  to  31, Tampa Bay 20
St. Lo over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13  31, Tampa Bay  to  31, Tampa Bay 20
Denver over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13  35, Jack to  35, Jacksonville 19
Seattle over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13  20, Tenne to  20, Tennessee 13
New En over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13 England 30, New Orleans 27  20, Tenne to  20, Tennessee 13
San Fr over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13 England 30, New Orleans 27 Francisco 32, Arizona 20  20, Tenne to  20, Tennessee 13
Dallas over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13 England 30, New Orleans 27 Francisco 32, Arizona 20  31, Wash to  31, Washington 16
 over  City 24, Oakland 7 Bay 19, Baltimore 17 Louis 38, Houston 13 England 30, New Orleans 27 Francisco 32, Arizona 20  31, Wash to  31, Washington 16
Cincinnati over Buffalo 27 to 24
Detroit over Cleveland 31 to 17
Kansas City over Oakland 24 to 7
Carolina over Minnesota 35 to 10
Pittsburgh over NY Jets 19 to 6
Philadelphia over Tampa Bay 31 to 20
Green Bay over Baltimore 19 to 17
St. Louis over Houston 38 to 13
Denver over Jacksonville 35 to 19
Seattle over Tennessee 20 to 13
New England over New Orleans 30 to 27
San Francisco over Arizona 32 to 20
Dallas over Washington 31 to 16