I am writing a program using both Assembly and c++ to collect user-inputted data. In my c++ file, I read in user numbers with a cin
loop:
while (cin >> input)
{
myArray.push_back(input);
}
cin.clear();
The user is also told to type CTRL-D
when finished. In my linked Assembly file I ask the user Are these numbers correct (y/n)?
Previously before updating to Ubuntu 19.04, I would do cin.clear()
as noted above after reading in the inputs so when I performed call getchar
back in my Assembly file, I could actually receive input from the user. However, after updating Ubuntu, my program only outputs the question if the numbers are correct and does not read in ’y/n‘
.
I have attempted cin.ignore()
as well after my cin loop but that does not seem to fix my issue. I can only assume that call getchar
in my Assembly file is reading some newline character rather than taking in a user input, but no matter the fixes I have found online, nothing seems to accept it.
For further clarification I am compiling/linking with g++ in my terminal and assembling with nasm. I can provide further code if needed. In Assembly, I am simply doing:
mov rax, 0
mov rdi, correctnumbersprompt ;This holds the string asking y/n
call printf
call getchar
I have found a fix.
To clear the stream state properly, I had to clear it from both my C++ file with
cin.clear();
and within my Assembly file, I cleared the stream by performing:This made it so I could successfully perform
call getchar
to grab user input after usingCTRL+D
to end an input stream.