在C++中,可以使用iostream库中的输入输出流对象来进行输入输出操作。
int num;
std::cout << "Enter a number: ";
std::cin >> num;
int num = 10;
std::cout << "The number is: " << num << std::endl;
double pi = 3.14159;
std::cout << std::setprecision(3) << pi << std::endl;
std::ofstream outfile("example.txt");
outfile << "Hello, World!";
outfile.close();
std::ifstream infile("example.txt");
std::string line;
while (std::getline(infile, line)) {
std::cout << line << std::endl;
}
infile.close();
需要包含头文件#include