gpt4 book ai didi

C++初学者关于输入/输出文本文件的问题。?

转载 作者:行者123 更新时间:2023-11-28 03:58:20 28 4
gpt4 key购买 nike

如果我有一个输入文本,其中唯一写的是“A”,并且我想要一系列代码来生成下一个 ASCII 集 (B),我该怎么做?

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

#include iostream>
#include fstream>
#include iomanip>
#include string>

using namespace std;

int main()
{

ifstream inFile;

ofstream outFile;

string firstName;
string lastName;
string character;

int age;
double rectangle, length, width, area, parameter, circle, radius, areaCircle, circumference, beginningBalance, interestRate, endBalance;

inFile.open("inData.txt");
outFile.open("outData.txt");

outFile << fixed << showpoint;
outFile << setprecision(2);

cout << "Data is processing..." << endl;

inFile >> length >> width;
area = length * width;
parameter = (length * 2) + (width *2);
outFile << "Rectangle:" << endl;
outFile << "Length = " << length << " " << "width = " << width << " " << "area = " << area << " " << "parameter = " << parameter << endl;

inFile >> radius;
outFile << " " << endl;
outFile << "Cricle:" <<endl;
areaCircle = 3.14159 * (radius * radius);
circumference = 2 * (3.14159 * radius);
outFile << "Radius = " << radius << " " << "area = " << areaCircle << " " << "circumference = " << circumference;

outFile << endl;
outFile << endl;

inFile >> firstName >> lastName >> age;
outFile << "Name: " << firstName << " " << lastName << "," << " " << "age: " << age;

outFile << endl;

inFile >> beginningBalance >> interestRate;
outFile << "Beginning balance = " << beginningBalance << "," << " " << "interest rate = " << interestRate << endl;
endBalance = ((18500 * .0350) / 12.0 ) + 18500;
outFile << "Balance at the end of the month = $" << endBalance;

outFile << endl;
inFile >> character;
outFile << "The character that comes after" << character << "in the ASCII set is" << character +1;



inFile.close();
outFile.close();

return 0;

}

最佳答案

与其将character 声明为string,不如将其声明为charstring 指的是std::string,一个用于存储多个字符的高级对象。 char 是一种低级 native 类型,它只存储 1 个字符。

char character;
infile >> character;
outfile << "next after " << character << " is " << char(character+1) << endl;

尽管输入了 Z 或字母。

关于C++初学者关于输入/输出文本文件的问题。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2307780/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com