std::getline for an ifstream but using a char* ins

2019-07-22 03:11发布

I want to use the getline function with a 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.

3条回答
Viruses.
2楼-- · 2019-07-22 03:47

Simple enough

char buffer[200];
cin.getline(buffer, sizeof buffer);

But there is no such thing as the string library, so your attempts not to include it are bound to be successful!

查看更多
爷、活的狠高调
3楼-- · 2019-07-22 03:50

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 );
查看更多
男人必须洒脱
4楼-- · 2019-07-22 04:08

you can use getline from istream

istream& getline (char* s, streamsize n );
查看更多
登录 后发表回答