这个编译器消息是什么意思 [英] What does this compiler message mean

查看:78
本文介绍了这个编译器消息是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





编译器给出一条消息:无法将istream转换为int。



我怎么能摆脱这个问题?(当然,



我必须将数组histData从输入文件传输到输出文件)



感谢您的帮助!



Hi,

Compiler gives a message: "could not cast an istream to int".

how can I get rid of this problem?( Of course,

I have to transfer an array histData from input file to output file)

Thanks for your help!

#include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <time.h>
  #include <ctype.h>
 #include <iostream.h>
 #include <iomanip.h>
 #include <string.h>
 #include <conio.h>
 #include <fstream.h>
 #include <except.h>

 using namespace std;
 const unsigned NAME_SIZE = 64;

 // The subroutine opens the input File and gives
 // it name inputFile.txt typed by a user under prompt
  // supplied by the main program
  void getInputFilename(char* inFile, fstream& f)
  {
   bool ok;

   do
    {
      ok = true;
      cout << "Enter input filename: ";
       cin.getline(inFile, NAME_SIZE);
      f.open(inFile, ios::in);
      if (!f)
        {
         cout << "Cannot open file " << inFile << endl << endl;
         ok = false;
          }
        }while (!ok);
  }//end getInputFile

  void getOutputFilename(char* outFile, const char* inFile, fstream& f)
  {
   bool ok;

   do
    {
      ok = true;
      cout << "Enter output filename: ";
      cin.getline(outFile, NAME_SIZE);
      if (stricmp(inFile, outFile) != 0)
        {
         f.open(outFile, ios::out);
       if (!f)
        {
          cout << "File " << outFile << " is invalid" << endl << endl;
          ok = false;
           }
        }
      else
       {
         cout << "Input and output filenames must be different!" << endl;
         ok = false;
        }
       } while (!ok);
   }//end getOutputFile

  // 1) opens P3M_New.txt as an inFile (lines of 3-digits integer numbers)
  // 2) writes P3M_New as an integer one-dimensional array *histData of maximal size=MAX


   int main()
    {
    fstream fin, fout;
    char inFile[NAME_SIZE + 1], outFile[NAME_SIZE + 1];

    getInputFilename(inFile, fin);


    const int MAX = 2500;
    int* histData;
    histData = new int[MAX];

    for(int i = 0; i < 2270; i++)
     histData[i] = -1;
    histData[2270]=1000;

    int j;
    j=0;
    while((int)cin.getline(inFile,NAME_SIZE) >> histData[j])
           {
           histData[j] = (int)cin.getline(inFile,NAME_SIZE);
           j++;
          }

    getOutputFilename(outFile, inFile, fout);
     for(int k = 0; k < 2270; k++)
    {
     fout << "histData(" << k << ") = " << histData[k] << "\n";
    }

    fin.close();
    fout.close();
    //deleting section
    delete [] histData;

   }//end main

推荐答案

这意味着写的是什么。



你不能将istream数据转换为整数数据或将其转换为整数数据类型。



请参考:

类型转换和类型安全(现代C ++) [ ^ ]

基本类型(C ++) [ ^ ]

istream [ ^ ]
It means exactly what is written.

You can NOT implicity cast or convert istream data to integer data type.

Please, refer this:
Type Conversions and Type Safety (Modern C++)[^]
Fundamental types (C++)[^]
istream[^]


这篇关于这个编译器消息是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆