字符串没有名为'subtr'错误的成员

string has no member named 'subtr' error

本文关键字:错误 成员 subtr 字符串      更新时间:2023-10-16

感谢您的阅读。我正在制作一个脚本来阅读这种格式的生日:月/日/年,并将年、日和月分开。我得到了年份部分,但对于日部分,我试图使用 string.subtr(,) 减去第二个"/"的位置值和最终的位置值。因此,例如,我正在尝试在findDay()函数中从01/26/1994获取01/26。但我似乎在第 55 行收到"字符串没有名为'subtr'的成员"错误。有人可以指导我吗,因为我是一个全新的程序员。另外,感谢您的持续帮助,因为在收到本网站的意见后,我的知识翻了一番。

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
void findYear(string &);
void findDay (string &);
void findMonth(string &);
int main()
{
    string birthday;
    cout << "Enter birthday: " << endl; // 01/26/1994
    cin >> birthday;
    string year = birthday;
    string day = birthday;
    string month = birthday;
    findYear(year);
    cout << year << endl;
    findDay(day);
    cout << day << endl;
    system("pause");
    return 0;
    int slashpos = birthday.find('/');
}
void findYear(string &year)
{
    int slashpos = year.find('/');
    int i = 0;
    string temp2;
while(year.at(year.length()-1-i)!='/')
    {
        temp2 += year.at(year.length()-1-i);
        i++;
    }
        string rtemp2 = "";
        for(int k = 0; k < temp2.length(); k++)
        {
            rtemp2 += temp2.at(temp2.length()-1-k);
            year = rtemp2; 
        }
}
void findDay (string &day)
{
    string tempday1 = "";
    string temp2 = "";
    int i = 0;
    tempday1 = day.subtr(day.rfind('/'),day.length()-1); /* error here! [Error] 'std::string' has no member named 'subtr'*/
    while(tempday1.at(tempday1.length()-1-i)!='/')
    {
        temp2 += tempday1.at(tempday1.length()-1-i);
        i++;
    }
        string rtemp2 = "";
        for(int k = 0; k < tempday1.length(); k++)
        {
            rtemp2 += tempday1.at(tempday1.length()-1-k);
            day = rtemp2; 
        }
}

它是substr的第二个s。子 STRing。