c++ - Why is std::cin outputting whatever is given to it? -
i've been working on learning c++, , 1 of first steps learning input , output. however, i've encountered issue where, when call std::cin , use put returned information variable, prints out whatever given it, whatever printed out on same line. code:
#include <iostream> int main() { using std::cout; using std::cin; using std::endl; cout << "hello world" << endl; cout << "testing "; int x; cin >> x; cout << x; return 0; }
returns:
c:\users\...\learncpp.exe hello world testing this5 testing 5 5 process finished exit code 0
it's noteworthy when entered 5, directly next this, in "this5", though there should space there. then, once hit enter, prints out should look, "this 5".
i've tried without space , same, , i've tried newline after "testing ", , prints 5 twice:
c:\users\...\learncpp.exe hello world testing 5 5 5 process finished exit code 0
i've scoured internet looking why, , i'm @ wits end. i'm using clion mingw , cmake. cmakelists.txt file looks like:
cmake_minimum_required (version 3.2) project (learncpp) set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11") set(source_files main.cpp) add_executable(learncpp ${source_files})
can see i'm doing wrong, or might wrong setup?
Comments
Post a Comment