国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
VC MFC獲得一個文本文件的行數(shù)
VC MFC獲得一個文本文件的行數(shù)
2010-03-06 22:55

#include "afx.h"
#include "string"
#include "fstream"
#include <iostream>
using namespace std;

int main()
{
float a[2000];
int i=0,line_num;
fstream file;
file.open(_T("text1.txt"),ios::in);
if (!file)
{
   cout<<"cannot open\n";
   return 0;
}
string str;
while(getline(file,str))
{
   file>>a[i];
   i++;
}
line_num=i+1;

file.close();
cout<<line_num<<endl;
for (int j=0;j<line_num;j++)
{
   cout<<"a["<<j<<"]="<<a[j]<<endl;
}
return 0;
}

#include <iostream>                        #include <fstream>                        using namespace std;                        int main(void)                        {                        char txtname[50];                        char getCh;                        const char BR = char(10);  //換行       等價于 '\n'                         unsigned short l = 0;                        cout<<"請輸入你要察看的文件名(全稱):";                        cin>>txtname;                        fstream myin(txtname, ios::in | ios::binary);                        if(NULL == myin)                        {                        cout<<"打開文件錯誤或沒有該文件,退出。"<<BR;                        exit(1);                        }                        while(myin.get(getCh))                        {                        if(BR == getCh) l++;                        }                        myin.close();                        cout<<"文件 "<<txtname<<" 有 "<<l<<" 行。"<<endl;                        return 0;                        }                        

 

#include "afx.h"
#include "string"
#include "fstream"
using namespace std;
ifstream   outfile;
outfile.open(_T("WestPosition.txt"),ios::in);
string   s;
int linenum=0;
   if (outfile)
   {
    while (outfile.getline((char *)s.c_str(),16))
   {
    linenum++;
   }

    outfile.close();
    CString cstr;
    cstr.Format(_T("行數(shù)為%d"),linenum);
    MessageBox(cstr);
   }
   else
   {  
  
    MessageBox(_T("open failed!"));
   }

讀取一行文本到rString,遇到回車換行符停止讀取

CStdioFile::ReadString(LPTSTR lpsz, UINT nMax);

  讀取一行文本到緩沖區(qū),遇到“0x0D,0x0A”時停止讀取,并且去掉硬回車“0x0D”,保留換行符“0x0A”,在字符串末尾添加“\0”(0x00)。nMax個字符里包含0x00這個字符。分析如下:

  1)如果nMax <= 字符數(shù),讀取(nMax-1)個字符 + 0x00

  2)如果nMax = 字符數(shù) + 1,讀取nMax個字符 + 0x00

  3)如果nMax > 字符數(shù),讀取nMax個字符 + 0x0A + 0x00

CStdioFile::ReadString(CString &rString);(重載)

  讀取一行文本到rString,遇到回車換行符停止讀取?;剀嚭蛽Q行符不讀到rString,而且末尾也沒有添加“\0”。

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C++中換行符/n與endl有什么區(qū)別
C++中對二進制文件的讀寫操作
C++中rdbuf()簡介及文件流的概念
sstream和strstream以及fstream
UC頭條:c 如何創(chuàng)建、修改及刪除文件
C++ 文件和流 | 菜鳥教程
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服