#include <iostream>
#include <cstring>
using namespace std;
int main() {
char test[20], test2[200];
cin.getline(test,20);
cin.getline(test2,200);
cout << strlen(test) << "'" << test << "'\n";
cout << strlen(test2) << "'" << test2 << "'\n";
return 0;
}
Takze co se stane, kdyz se zada retezec napriklad 50 znaku? nacte se 19znaku do test, zbytek radku se zahodi, \n evidentne zustane protoze test2 je prazdny a program skoncil. Problem solved:
12345678901234567890ASSDFGHJKLWERTZUIDFGHJKL
19'1234567890123456789'
0''
kratsi nez 19 se nacte a pak se ceka na dalsi radek pro druhy retezec... \n se ve fronte nenechava
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char test[20], test2[200];
cin.get(test,20);
cin.get(test2,200);
cout << strlen(test) << "'" << test << "'\n";
cout << strlen(test2) << "'" << test2 << "'\n";
return 0;
}
Get se chova trosku jinak:
12345678901234567890ASSDFGHJKLWERTZUIDFGHJKL
19'1234567890123456789'
25'0ASSDFGHJKLWERTZUIDFGHJKL'
u kratsiho retezce necha \n ve fronte - tj. druhej get nic nenacte