我需要从TXT读取文本,将里面的数据处理后作为OPC的点的参数

解决方案 »

  1.   

    scanf, gets之类stdio.h里的东西
      

  2.   

    读取TXT的语句应该怎么写?新人来着,麻烦能详细点么,谢谢
      

  3.   

    FILE* fp = fopen( W2A( strFileName ), "rb");
    if ( fp == NULL )
    {
    fp = fopen( W2A( strFileName ),"rb");
    if ( fp == NULL )
    {
    return ;
    }
    } LocalLog* pLog = new LocalLog;
    memset(pLog, 0, sizeof(LocalLog));
    int nCount = 0;
    while ( fread(pLog, sizeof(LocalLog),1,fp) != NULL )
    {
    nCount++;
    FillQueryInfo( *pLog, nCount);

    delete pLog;
    fflush(fp);
    fclose(fp);
    这个是已数据结构来读的,你也可以改成一行一行来读
      

  4.   

    Example/* FOPEN.C: This program opens files named "data"
     * and "data2".It  uses fclose to close "data" and
     * _fcloseall to close all remaining files.
     */#include <stdio.h>FILE *stream, *stream2;void main( void )
    {
       int numclosed;   /* Open for read (will fail if file "data" does not exist) */
       if( (stream  = fopen( "data", "r" )) == NULL )
          printf( "The file 'data' was not opened\n" );
       else
          printf( "The file 'data' was opened\n" );   /* Open for write */
       if( (stream2 = fopen( "data2", "w+" )) == NULL )
          printf( "The file 'data2' was not opened\n" );
       else
          printf( "The file 'data2' was opened\n" );   /* Close stream */
       if( fclose( stream ) )
          printf( "The file 'data' was not closed\n" );   /* All other files are closed: */
       numclosed = _fcloseall( );
       printf( "Number of files closed by _fcloseall: %u\n", numclosed );
    }
    OutputThe file 'data' was opened
    The file 'data2' was opened
    Number of files closed by _fcloseall: 1
      

  5.   

    strFileName 是换成文件的名字么?
    从TXT里得到的数据存在哪个变量里了?
      

  6.   

    CFile::Read()
    CStdioFile::ReadString()
      

  7.   

    CStdioFile fileR; SReadTxtFilePathName = _T("d:\\abc.txt") if( !fileR.Open(SReadTxtFilePathName,CFile::modeRead|CFile::shareExclusive|CFile::typeText) )
    {
    AfxMessageBox( _T("读文件出错:\n" ) + SReadTxtFilePathName );
    // return;
    }// fileR.SeekToBegin (); while(fileR.ReadString(SReadStr))
    { //SReadStr 就是每一行的内容。 }
    fileR.Close();
      

  8.   

    我要把TXT的数据存入数组,应该怎么写?
      

  9.   

            char path[256];
    GetCurrentDirectory(256,path);//应用程序所在路径
    CString filepath = path;
    filepath += "\\data.txt";//你的文件的绝对路径,假设你的文件名是data.txt CStdioFile m_file(filepath,CFile::modeRead);
    CString contents;
    while (m_file.ReadString(contents))//逐行读取文本内容
    {
                    //contents中保存的就是"data.txt"文件中每一行的内容.可以使用了

    }
      

  10.   

    读出数据存入数组 用fscanf最方便