[英]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.