I am so confused after reading that code. First of all you never initialize text, you just add 1 to it in the loop (absolutely NO idea what this would solve) and then output it before the program is done. Also what exactly is while (cin.get(znak)) { supposed to do?
Looks to me like that loop would never go through because you never did a cin >> znak; above it. I'm also a little confused about what you're trying to do. Are you writing a program that just spams random characters in console until the end of the line then stop? Sorry if I'm a little wrong here, still fairly new myself to C++ but this doesn't look right. ;)
I just coded a little program to do what I think you're trying to do. I'm not sure if this would work as I just coded it in the forums, so I haven't actually compiled to see if it works error free. I have a feeling it won't work for a few reasons, but you can give it a shot. Let me know what happens I'm curious. ;D
this pice of code on which I'm learng wright now is copyed from my book.
refering to my book this code shall initialize string with characters including whitespaces.
the point of this code is "including whitespaces" cos cin >> ignores whitespaces.
yeah I'm confused too :/
EDIT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#inlucde <cionio.h>
#include <string>
usingnamespace std;
int main () {
string text;
char znak;
while (cin.get(znak)){
if (znak == '\n') break;
text += znak; // here was the problem ^^
}
cout << text;
_getch();
return 0;
}