2013-08-26 99 views
0

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

代码: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(); 
} 

实施例输出();

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 
+0

每隔一段时间?你在进什么? –

+0

这可能解释您的问题。它是否正在阅读你的换行符? http://stackoverflow.com/questions/2012268/cin-get-and-omitting-newline-char – dcaswell

+0

你是否在使用'\ r \ n'的系统上输入密码,因为它是换行符分隔符? – KitsuneYMG

回答

2

cin.get()没有得到'\n'您键入〜

尝试使用,

string str; 
getline(cin, str) 

代替cin.get()

或添加getchar()cin.get()

+0

getline(cin,str)完美工作!我不得不添加#包括 user908759

0

辛格Ë你是在Windows上:

#include <conio.h> 

// .. your other stuff 

_getch(); 

cin.get()是要抓住无论是在输入缓冲区(如果你按下回车,或者空间,或几乎闻到了键盘上,也将有一些),或者EOF如果没有任何东西,所以它会一直返回。