2013-11-15 2 views
-7

읽어 주셔서 감사합니다. 월/일/년 형식으로 생일을 읽고 연도, 일 및 월을 구분하는 스크립트를 만들고 있습니다. 나는 1 년 파트를 얻었지만, 하루 파트에서는 ​​string.subtr (,)을 사용하여 두 번째 '/'위치 값과 최종 위치 값을 뺍니다. 예를 들어, findDay() 함수에서 01/26/1994에서 01/26을 얻으려고합니다. 하지만 "문자열에 'subtr'이라는 오류가있는 멤버가 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; 
     } 
} 
+1

'std :: string :: substr'이 필요합니다. – juanchopanza

답변

3

그것은 2 ssubstr입니다. SUB- S TRing.

+0

어리 석다. 고마워요! – NewProgrammer