C++ 在文本文件(c+;+;)中逐行向前移动
我一直在开发一个程序,该程序设计用于从文本文件的几行中读取数据。我对第一条线没有问题,但我不知道如何进入第2、3号线,等等 未设置文件的内容和长度,但内容可以如下所示:C++ 在文本文件(c+;+;)中逐行向前移动,c++,C++,我一直在开发一个程序,该程序设计用于从文本文件的几行中读取数据。我对第一条线没有问题,但我不知道如何进入第2、3号线,等等 未设置文件的内容和长度,但内容可以如下所示: 1.01.0 C 1.01.0伏 1.01.0秒 1.01.0 D 1010.0 250.0摄氏度 999 这是我的计划(到目前为止) #包括 #包括 #包括 #包括 #包括 使用名称空间std; int main() { 双半径; 双高; 字符字母[1]; char Exercise4[80]=“Exercise4.txt”
1.01.0 C
1.01.0伏
1.01.0秒
1.01.0 D
1010.0 250.0摄氏度
999
这是我的计划(到目前为止)
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
双半径;
双高;
字符字母[1];
char Exercise4[80]=“Exercise4.txt”;
河流充填;
填充开放式(练习4);
填充>>半径>>高度>>字母;
while(半径!=999){
大概
while(infile >> radius >> height >> letter) {
// process, radius height and letter
}
应该把你扭曲到你想去的地方
输入行
999
将停止该循环。我建议:
...
infile.open (Exercise4);
while((infile >> radius) && radius!=999 && (infile >> height >> letter)) {
...
}
当遇到半径999或到达文件末尾时,无论先发生什么,都会停止读取。我建议您使用
std::ifstream-fin(“myFile.txt”);
for(std::string行;std::getline(fin,line);)
{
std::无法复制的
...
infile.open (Exercise4);
while((infile >> radius) && radius!=999 && (infile >> height >> letter)) {
...
}
std::ifstream fin("myFile.txt");
for (std::string line; std::getline(fin, line); )
{
std::cout << line << std::endl;
}