如何计算行数 我用一个CString的变量去读取了 TXT的内容 那么如何计算行数呢 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 INT i = -1; INT c = 0; do { i = s.Find(_T('\n'), i + 1); ++c; } while (i != -1 && i != s.GetLength() - 1); 更土一点的办法,循环 CStdioFile.ReadStringint nCount = 0;while (CStdioFile.ReadString(...)){ nCount++;}但是效率上就没有直接查找 "\n" 来的快了。只是作为一种思路。 有个问题,可能会漏掉最后一行,CString strText(_T(""));strText="....";//保存你的文件内容int flag=-1;int nCount=0;while(-1!=(flag=strText.Find("\r\n")){ nCount++; strText=strText.Right(strText.GetLength()-flag-2);}if(!strText.IsEmpty()) //最后一行内容{ nCount++;}CString str(_T(""));str.Format(_T("%d"),nCount);AfxMessageBox(str); 对于上的strText,可以先过滤某一些字符,如strText.Trim(_T(" \r\n")); com组件调试CoCreateInstance函数 VC读取txt文件中的XYZ坐标的问题 std::find,std::find_end,std::find_if 三者有什么区别?它们中谁的效率比较高? 响应回车键 请问如何在MFC中实现文件的读取 如何取消热键转移符。 怎么在一个对话框A类中对另一个对话框B的Cancel按钮操作(关闭对话框B)? 关于GPS通信的问题 关于VC6.0断点不可用的问题 那里有atl入门书啊 DirextX media Object 关于树控件的问题?谢谢回答
INT c = 0;
do
{
i = s.Find(_T('\n'), i + 1);
++c;
} while (i != -1 && i != s.GetLength() - 1);
int nCount = 0;
while (CStdioFile.ReadString(...))
{
nCount++;
}
但是效率上就没有直接查找 "\n" 来的快了。
只是作为一种思路。
有个问题,可能会漏掉最后一行,
CString strText(_T(""));
strText="....";//保存你的文件内容
int flag=-1;
int nCount=0;
while(-1!=(flag=strText.Find("\r\n"))
{
nCount++;
strText=strText.Right(strText.GetLength()-flag-2);
}
if(!strText.IsEmpty()) //最后一行内容
{
nCount++;
}CString str(_T(""));
str.Format(_T("%d"),nCount);
AfxMessageBox(str);