字符串而不是 Cstring c++
String instead of Cstring c++
#include <fstream>
#include <iostream>
using namespace std;
int main ( )
{
fstream f;
char cstring[256];
f.open ( "test.txt", ios::in );
short counter = 0;
while ( !f.eof ( ) )
{
f.getline ( cstring, sizeof ( cstring ) );
counter++;
cout << cstring << endl;
}
cout << "Anzahl der Zeilen:" <<counter << endl;
f.close ( );
system ( "PAUSE" );
}
我想用 std::string 替换 Cstring,但 f.getline 不将其作为参数。
成员函数getline()
仅适用于原始字符数组。现代C++提供了可用于std::string
的免费功能std::getline()
:
#include <string>
std::string str;
while (std::getline(f, str)) {
}
相关文章:
- 在C++中使用Cstring反转字符串
- 如何转换真实路径 CString c++
- __int64 CString 返回错误的值 - C++ MFC
- 如何将 SHFileOperation() 与 CString 路径一起使用
- 在_T值中使用 CString
- 没有大小参数的CString::GetBuffer()做什么
- 如何将 CString 转换为字节 [] 数组?
- 可视化 如何将 CString 值列表添加到 MFC C++ 中的组合框中?
- C++从 std::string 创建 CString 失败
- 对树节点使用 CString 时出现内存泄漏
- C++ 巨大 CString 的串联
- 无法从字符构造CString
- 将旧 cstring 的标记连接成新的 C 字符串
- 如何将 CComVariant bstr 转换为 CString
- C++ cstring 查找和替换
- 使用_tcscpy_s将 CString 复制到 TCHAR*
- StringCch* functions and Cstring
- 循环以使用 cstring 数组 c++ 获取用户输入
- 使用指针 c++ 反转函数中的 cstring 数组
- 如何将CString转换为使用WCHAR的Windows API和自定义函数?