When I'm trying to access classes public variable (in this case trying to input text row) it shows that it's uninitialized. However, I declared it in class as a public variable. I know that's some dummy mistake, but can't find it :D
#include <iostream>
#include <conio.h>
using namespace std;
class stringlength {
private:
int lengt;
public:
char * row;
int len()
{
for (int i = 0, lengt = 0; (*(row + i) != '\0'); i++, lengt++) {}
return lengt;
}
};
int main()
{
stringlength test;
cout << "Enter a string:";
cin >> test.row;
cout << "Length is: " << test.len();
_getch();
}
This program is expected to give a length of the inputted row (like strlen function) Error is:
Error C4700 uninitialized local variable 'test' used
Thanks for help ;)
row, you also need to allocate some memory to store the string in. Have a look at the list of good books.std::string? It's easier to use and harder to miss use. And it's have a.size()row. stackoverflow.com/questions/15319690/char-and-cin-in-c may help