首页 > 解决方案 > Correct input method for array of char?

问题描述

So I have this:

char *nume = new char[100];

What is the correct way to input into this char:

cin>>nume;

or

cin.getline(nume,100);

or something else?

标签: c++char

解决方案


usingcin >>只会读取第一个单词。
cin.getline读取字符直到行尾或指定的分隔符。

所以这取决于你想要做什么,但似乎你正在准备一个 100 个字符的缓冲区,所以你可能正在寻找cin.getline,除非你知道不会有空格(读取长哈希)或者你想要在第一个词之后停止,然后你可以去cin >>


推荐阅读