Hi i am trying to make a program that gets string and divide it by new line which is \n. i noticed that if i assign a string into a variable and run the program it works fine. However if i get input from getline and assign it, the code does not work. anyone knows why??
the code looks like this. I think if i get string from getline function, the if statement can't recognize where '\n' is..!!
and This is not complete code!! i just posted the part i get error!!
.
.
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
while(getline(cin,line)) {
for (int i = 0; i < line.size(); i++) {
if(line[i] == '\n') {
str_len = i-init_str;
lines.push_back(line.substr(init_str,str_len));
str_len == 0;
init_str = i+1;
}
elseif(line[i] != '\n' && i == line.size()-1) {
lines.push_back(line.substr(init_str));
}
}