c++복습 2-6~2-8
2-6
#include <iostream>
#include <cstring>
using namespace std;
int main(void) {
char pw[100];
char pw2[100];
cout << "enter new pw>>>";
cin.getline(pw, 100, '\n');
cout << "enter new pw again>>>";
cin.getline(pw2, 100, '\n');
if (strcmp(pw, pw2) == 0)
cout << "same";
else
cout << "wrong";
return 0;
}
2-7
#include <iostream>
#include <cstring>
using namespace std;
int main(void) {
while ((true))
{
char ans[100];
cout << "enter yes >>";
cin.getline(ans, 100, '\n');
if (strcmp(ans,"yes")==0) {
cout << "exit...";
break;
}
}
return 0;
}
2-8
#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
char name[100];
char maxName[100]="";
cout << "5명의 이름을 ;으로 구분하여 입력\n>>";
for (int i = 0; i < 5; i++) {
cin.getline(name, 100, ';');
cout << i + 1 << " : " << name<<endl;
if (strlen(name) > strlen(maxName)) {
strcpy_s(maxName, name);
}
}
cout << maxName;
return 0;
}