小编Dav*_*ang的帖子

EOF,在读取最后一行时永远循环.C++

void ReadTheData(ifstream& in_stream, ofstream& out_stream)
{
    using namespace std;
    int id;
    char name[100] = "";
    double balance;
    in_stream >> id >> name >> balance;
    while(name[0] || ! in_stream.eof()) // Continue looping until eof or name is not      present.

    {
        cout << id << '\t' << name << '\t' << balance << endl;
        in_stream >> id >> name >> balance;
    }

}

the Balance.txt has format style:
4248749 Kelly_E     460.02
8898693 Kelly_George_MD 1764.68
4597789 Lambert_Richard 1571.79
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,文件Balance.txt中的最后一行进入无限循环,如何停止无限循环?

c++ eof

1
推荐指数
1
解决办法
1133
查看次数

如何理解复杂的数组声明指针,和

这是两行代码:

int (*parry)[10]   = &arr   // Line # 1
int *(&arrRef)[10] = ptrs   // Line # 2
Run Code Online (Sandbox Code Playgroud)

第1行:

parry是一个指向int大小为10 的数组的指针.
它是否意味着:

  • parray[1]指向的地址arr,
  • parray[2] 要点的 arr
  • ...
  • parray[10]要点或arr

Line # 1什么时候用?

解:

#include <iostream>
int main(
{
 int arr[10] = { 3, 54  };
 int (*parry)[10] = &arr;
 std::cout << (*parry)[0] << " " << (*parry)[1] << " "  << (*parry)[3] << "  " << parry[4] << std::endl;
 return …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers

1
推荐指数
1
解决办法
158
查看次数

标签 统计

c++ ×2

arrays ×1

eof ×1

pointers ×1