ifstream的std :: getline,但使用char *而不是字符串 [英] std::getline for an ifstream but using a char* instead of a string

查看:112
本文介绍了ifstream的std :: getline,但使用char *而不是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将getline函数与char*一起使用.

I want to use the getline function with a char*.

我不想使用std::string,因为我有一个函数将char*作为参数并写入其中,并且我不想为字符串编写一个全新的函数.

I don't want to use std::string because I have a function that takes char* as parameters and writes to them and I don't want to write a whole new one just for strings.

推荐答案

一个简单问题的简单答案:使用流的成员函数 getline代替免费函数.

Simple answer for a simple question: use the stream's member function getline instead of the free function.

#include <fstream>

...

std::fstream my_stream;
char buffer[ 1000 ];

my_stream.getline( buffer, sizeof buffer );

这篇关于ifstream的std :: getline,但使用char *而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆