字符串没有名为'subtr'错误的成员
string has no member named 'subtr' error
感谢您的阅读。我正在制作一个脚本来阅读这种格式的生日:月/日/年,并将年、日和月分开。我得到了年份部分,但对于日部分,我试图使用 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。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++错误消息*成员参考.**初学者*
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 在运算符重载定义中使用成员函数(const错误)
- 错误:请求非类类型为"MULTIMEDIA_FILME [500]"的成员|
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 静态成员函数使用相同的名称时出现模板类型名称错误
- 为什么即使我声明了朋友类,我也会收到错误"无法访问类中声明的私人成员"
- 为什么我在空指针错误(链表)中获取成员访问权限
- WinLamb 错误:成员初始化非法
- 类成员值的合法或错误成员用法
- for 循环说 - 错误 成员引用基类型"int [13]"不是结构或联合
- C++错误:成员声明末尾的预期“;”
- C++:错误:成员访问不完整的类型,未使用的参数[-Werror,-Wunused-parameter]
- 错误:成员函数不能在其类之外声明
- 初始化 cpp 文件中的私有静态成员变量.错误:成员是私有的
- 错误:成员访问不完整类型:前向声明
- 错误:成员不可访问
- 指向基类错误成员函数的指针