我想读取record.txt的第3行内容并输出,结果输出的还是第一行的内容,怎么回事啊?
程序代码:
ifstream ss("c:\\record.txt");
ss.seekg(2,ios::beg);
CDC* cc=GetDC();
char str[100];
ss.getline(str,100);
cc->TextOut(100,100,str);record.txt的内容
▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
1122
1133
1144
2323
454677

解决方案 »

  1.   

     
    basic_istream<Elem, Tr>& seekg(
         pos_type _Pos
    );
    basic_istream<Elem, Tr>& seekg(
         off_type _Off,
          ios_base::seekdir _Way
    );
     Parameters
    _Off
    An offset to move the read pointer relative to way. _Pos
    The absolute position in which to move the read pointer. _Way
    One of the ios_base::seekdir enumerations. 
      

  2.   

    嗯,是,seekg()是对输入文件定位,它第一个参数是偏移量,表示字节数,而不是行数你可以用查找函数找到第二个换行符的偏移量,然后+1,再用这个偏移量作为seekg()函数的第一个参数,再getline就行了