计算文本文件中的整数个数(未声明的标识符使用 fin>>x)
Counting number of integers in text file (undeclared identifier using fin>>x)
我有一个包含未知数量整数的文本文件。我毫不费力地创建了一个动态数组,但数字的间距和数字各不相同。我通常会遍历每个位置来计算使用的 space 的数量,从中减去 space,但在这种情况下这不起作用。
我想用这样的东西:(类似的问题会建议)
do
{
if (!file.is_open())
{
file.open(donation);
}
fin >> temp;
charCount++;
}
while (file.peek() != EOF);
cout << charCount;
现在,我包含了 fstream,我使用的是 namespace std,打开和读取文本文件没有问题,但是 visual studio 2015 告诉我:
错误 C2065 'fin': 未声明的标识符
我不明白我在做什么会触发 IDE 的那种类型的响应。
file
是你的 ifstream
的名字吧?如果是这样,行
fin >> temp;
应该是
file >> temp;
我有一个包含未知数量整数的文本文件。我毫不费力地创建了一个动态数组,但数字的间距和数字各不相同。我通常会遍历每个位置来计算使用的 space 的数量,从中减去 space,但在这种情况下这不起作用。
我想用这样的东西:(类似的问题会建议)
do
{
if (!file.is_open())
{
file.open(donation);
}
fin >> temp;
charCount++;
}
while (file.peek() != EOF);
cout << charCount;
现在,我包含了 fstream,我使用的是 namespace std,打开和读取文本文件没有问题,但是 visual studio 2015 告诉我:
错误 C2065 'fin': 未声明的标识符
我不明白我在做什么会触发 IDE 的那种类型的响应。
file
是你的 ifstream
的名字吧?如果是这样,行
fin >> temp;
应该是
file >> temp;