I am not sure about your problem but I have a few tips for you. When you are using C++ then you should use std::cout
and std::cin
for input and output. They are stream from library <iostream>
. You can also write using namespace std;
and then you needn't write std::
. Function printf()
comes from C and is type unsafe so you shouldn't use it in C++.
Also streams offer many functions for getting information about successful or unsuccessful reading/writing etc. I really recommend it to you.
Method cin.get()
reads only 1 character and it also can be a white character ( '
', ' ', ' ' ). If you would like read number and ignore white spaces ( in default they are used like separators ) then you can use this code:
int x;
cin >> x;
if ( cin.fail() ) cout << "Reading error. It is not a number." << endl;
// cin.eof() means end of file, in this case it is end of input stream
I know when you want read something then user have to write requested data and '
'. Character '
' is important. I have never tried it but I think that it can be redefined. I read it somewhere.
I hope that my tips are helpful
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…