处理我需要实现子字符串知识的分配,但我遇到了编译错误。
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>
#include <string.h>
using namespace std;
int main() {
string K;
cout << "Sisestage isikukood:\n ";
getline(cin, K);
/* Küsin kasutajalt isikukoodi*/
std::string str2 = K.substr(1, 1);
std::string str3 = K.substr(2, 2);
std::string str4 = K.substr(4, 2);
std::string str5 = K.substr(6, 2);
cout << "Isikukoodi I andmed:\n ";
if(std::string str2 == "1") {
cout << " *mees\n";
} else if(std::string str2 == "2") {
cout << " *naine\n";
} else if(std::string str2 == "3") {
cout << " *mees\n";
} else if(std::string str2 == "4") {
cout << " *naine\n";
} else if(std::string str2 == "5") {
cout << " *mees\n";
} else if(std::string str2 == "6") {
cout << " *naine\n";
}
std::cout << "* sundis " << str3 << "." << str4 << ".";
else if(std::string str2 == "2" || std::string str2 == "1") {
cout << "18" << str5 << ;
} else if(std::string str2 == "3" || std::string str2 == "4") {
cout << "19" << str5 << ;
} else if(std::string str2 == "5" || std::string str2 == "6") {
cout << "20" << str5 << ;
}
} else { /*Tulemus,kui isikukuud on sisestatud valesti*/
cout << " Sisestasite isikukoodi " << K << " nime valesti.Palun proovige uuesti.\n";
}
getch();
return 0;
}
C:\programs\c\Untitled1.cpp: In function `int main()':
C:\programs\c\Untitled1.cpp:19: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:19: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:24: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:24: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:28: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:28: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:32: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:32: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:36: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:36: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:40: error: expected primary-expression before "str2"
C:\programs\c\Untitled1.cpp:40: error: expected `)' before "str2"
C:\programs\c\Untitled1.cpp:45: error: expected primary-expression before "else"
C:\programs\c\Untitled1.cpp:45: error: expected `;' before "else"
C:\programs\c\Untitled1.cpp:49: error: expected primary-expression before "else"
C:\programs\c\Untitled1.cpp:49: error: expected `;' before "else"
C:\programs\c\Untitled1.cpp:53: error: expected primary-expression before "else"
C:\programs\c\Untitled1.cpp:53: error: expected `;' before "else"
C:\programs\c\Untitled1.cpp: At global scope:
C:\programs\c\Untitled1.cpp:59: error: expected unqualified-id before "else"
C:\programs\c\Untitled1.cpp:59: error: expected `,' or `;' before "else"
C:\programs\c\Untitled1.cpp:62: error: expected constructor, destructor, or type conversion before ';' token
C:\programs\c\Untitled1.cpp:63: error: expected unqualified-id before "return"
C:\programs\c\Untitled1.cpp:63: error: expected `,' or `;' before "return"
C:\programs\c\Untitled1.cpp:64: error: expected declaration before '}' token
Execution terminated