类似这样的txt文档,要怎么读取啊?

解决方案 »

  1.   

    楼主你好
            下面的文档供你参考
    http://zhidao.baidu.com/question/687790914115405644.html
      

  2.   

    单纯用cfile或者C语言里的读取可以吗?我新手,看起来有点费劲
      

  3.   

    CFile一次读取到CString对象中,然后利用CString::Tokenize()以\r\n作为分隔符来拆分字符串得到各个子串信息
      

  4.   

    都可以啊
    http://blog.csdn.net/lh3325251325/article/details/4761575
      

  5.   

    都可以啊
    http://blog.csdn.net/lh3325251325/article/details/4761575有参考作用,但是我没法把cstring转成double数组,最后我是要把TXT的数据存入double数组使用才行
      

  6.   

    试试:
    CStdioFile cf;
    CString OneLine;
            double db[100];
            int idx=0;
    if(cf.Open("tmp.txt",CFile::modeRead | CFile::typeText))
    {
    while (cf.ReadString(OneLine))
    {
    sscanf(OneLine,"%f",db[idx]);
    }
    cf.Close();
    }
      

  7.   

    1    (LPSTR)(LPCSTR) OneLine
    2   OneLine.GetBuffer(OneLine.);
      

  8.   

    1    (LPSTR)(LPCSTR) OneLine
    2   OneLine.GetBuffer(OneLine.GetLength( ));
      

  9.   

    1  sscanf((LPSTR)(LPCSTR) OneLine,"%f",db[idx]);
    2  sscanf(OneLine.GetBuffer(OneLine.GetLength( )),"%f",db[idx]);
      

  10.   

    少了一句
    sscanf((LPSTR)(LPCSTR) OneLine,"%f",db[idx]);
    idx++;idx 不能超过 99, 因为 double db[100]; 只有100 个
      

  11.   

    CStdioFile cf;
    CString OneLine;
            double db[100];
            int idx=0;
    if(cf.Open("tmp.txt",CFile::modeRead | CFile::typeText))
    {
    while (cf.ReadString(OneLine))
    {
    sscanf((LPSTR)(LPCSTR) OneLine,"%f",db[idx]);
    idx++;
    }
    cf.Close();
    }
      

  12.   

    vc6 上 没问题的 语句 !
    那就用
    2  sscanf(OneLine.GetBuffer(OneLine.GetLength( )),"%f",db[idx]);
      

  13.   

    你的 是 UNCODE 版本 !sscanf, swscanf
    Read formatted data from a string.int sscanf( const char *buffer, const char *format [, argument ] ... );int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );Routine Required Header Compatibility 
    sscanf <stdio.h> ANSI, Win 95, Win NT 
    swscanf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT 
    For additional compatibility information, see Compatibility in the Introduction
      

  14.   

    // 查MSDN,sscanf,找到unicode版本,或者 ANSI和unicode都可用的那个宏
      

  15.   

    swscanf((LPCWSTR)OneLine.GetBuffer(OneLine.GetLength( )),L"%f",db[idx]);
      

  16.   

    我把vs的配置环境改成多字符了,然后调用那个数字用teechart显示绘图,出来以后是一条直线。。
      

  17.   

    我把vs的配置环境改成多字符了,然后调用那个数字用teechart显示绘图,出来以后是一条直线。。
      

  18.   

    你的txt到底是什么数据 ?point ?
      

  19.   

    看看 double db[100]; 里 东西 对不对 , (如果 函数 外 用 加 改为 全局变量 !)
    while 里 sscanf 后加一句
    afxDump << db[idx];
      

  20.   

    "加了这句" 在 debug 输出 窗口 看 数字对不对。
      

  21.   

    point 为什么 不是 一行 一个   x,y  ?
    而且 “222751” 也不是 浮点数, 是 整数 ?
    仔细看看 sscanf 的 format 和 type
      

  22.   

    sscanf(OneLine.GetBuffer(OneLine.GetLength( )),"%f",db[idx]);
    %f 是浮点格式,改为
    int  data[100];
     sscanf(OneLine.GetBuffer(OneLine.GetLength( )),"%d",data[idx]);
      

  23.   

    public byte[string] ReadTxt()
    {
    List<string> result = new List<string>();
    try
    {
    using (StreamReader streamReader = new StreamReader(this.FilePath, this.EncodingType))
    {
    while (streamReader.Peek() > 0)
    {
    result.Add(streamReader.ReadLine());
    }
    }
    }
    catch
    { }
    return result.ToArray();
    }
      

  24.   

    这个是我项目中的代码
    一个参数是 你txt的路径,一个是编码格式,你写txt是哪种 那么你读取的时候也是哪种,如果你不知道哪种就default或者一个个试过来UTF8 UTF7 ASC.等待
      

  25.   

    用fgets,sscanf实现。