繁体   English   中英

C ++ for循环跳过cin.get()

[英]C++ for loop skips cin.get()

在这个for循环中cin.get(); 每隔一段时间都会被跳过。 我不知道为什么会被跳过。 任何帮助将不胜感激。

码:

for(Pointer = StartPointer; Pointer < EndPointer; Pointer += MemInfo.RegionSize)
{

    VirtualQueryEx(hProc, (LPCVOID)(Pointer), &MemInfo, sizeof(MemInfo));
    cout << "MemInfo AllocationBase: " << MemInfo.AllocationBase << endl;
    cout << "MemInfo AllocationProtect: " << MemInfo.AllocationProtect << endl;
    cout << "MemInfo BaseAddress: " << MemInfo.BaseAddress << endl;
    cout << "MemInfo Protect: " << MemInfo.Protect << endl;
    cout << "MemInfo RegoinSize: " << MemInfo.RegionSize << endl;
    cout << "MemInfo State: " << MemInfo.State << endl;
    cout << "MemInfo Type: " << MemInfo.Type << endl;
    cout << "MemInfo Size: " << sizeof(MemInfo) << endl;
    cout << "Starter pointer is: " << StartPointer << endl;
    cin.get();
}

cin.get()之间的输出示例;

MemInfo AllocationBase: 00000000
MemInfo AllocationProtect: 0
MemInfo BaseAddress: 00000000
MemInfo Protect: 1
MemInfo RegoinSize: 65536
MemInfo State: 65536
MemInfo Type: 0
MemInfo Size: 28
Starter pointer is: 0
MemInfo AllocationBase: 00010000
MemInfo AllocationProtect: 4
MemInfo BaseAddress: 00010000
MemInfo Protect: 4
MemInfo RegoinSize: 65536
MemInfo State: 4096
MemInfo Type: 262144
MemInfo Size: 28
Starter pointer is: 0

cin.get()没有得到你键入的'\\n' cin.get()

试着用,

string str;
getline(cin, str) 

而不是cin.get()

或者在cin.get()之后添加一个getchar() cin.get()

因为你在Windows上:

#include <conio.h>

// .. your other stuff

_getch();

cin.get()将抓住输入缓冲区中的任何内容(如果你按下了输入,空格,或者几乎在键盘上呼吸,它会有东西),或者如果没有任何东西则EOF ,所以它会总是回来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM