簡體   English   中英

如何從標准輸入讀取單個字符

[英]How to read a single character from stdin

我需要編寫一個程序,如果符號為+,則編寫A+B,如果符號為-,則編寫AB,但我不知道如何聲明+或-的變量。 提前致謝!

奇怪的是,我找不到合適的副本。

#include <iostream>
int main(int argc, char **argv)
{
    char c;
    std::cin >> c;
    std::cout << "this is the char I got: " << c << "\n";
    return 0;
}

編譯你的程序

$ g++ main.cpp -o main

然后運行它:

$ ./main
+
this is the char I got: +

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM