Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22057

std::cin not working inside of a for loop [closed]

$
0
0

I'm using mingw on windows. Maybe I'm dumb or it's an error, but cins inside of a for-loop are just not working.This was the best code snippet I could image to demonstrate the problem...

#include <iostream>#include <string>int main(){  std::string x;  for (int i; i < 10; i++)  {    char y;    std::cin >> y;    x += y;  }  std::cout << x;}

If I compile and run, I don't get prompted with the input. It just runs trough. I thought maybe it's an input buffer thing, but I spammed a lot of cin.ignores, so that can't really be the problem.


Viewing all articles
Browse latest Browse all 22057

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>