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

标签 c++ for-loop cin

在这个 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'~

尝试使用,

string str;
getline(cin, str) 

代替 cin.get()

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

关于C++ for 循环跳过 cin.get(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18451560/

相关文章:

C++ Diamond 控制台输出问题

c++ - 如何将相同的签名分配给具有不同签名的函数?

c++ - 读取文本文件并将其内容存储在 c++ 中的 unoredered_map 中

javascript - 确定排队的票是否有足够的零钱——1 个测试用例失败

Numpy 的 Python 列表理解

c++ - `cin` 在 Mac 上错误地解析 `double` 输入

c++ - Qt:单实例应用保护的最佳实践

c++ - 链接失败,怎么回事?

java - 当没有匹配时陷入循环 - Java

c++ - 更智能的方式来实现这个 switch 语句