c++ - 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?
解决方案
usingcin >>
只会读取第一个单词。
cin.getline
读取字符直到行尾或指定的分隔符。
所以这取决于你想要做什么,但似乎你正在准备一个 100 个字符的缓冲区,所以你可能正在寻找cin.getline
,除非你知道不会有空格(读取长哈希)或者你想要在第一个词之后停止,然后你可以去cin >>
推荐阅读
- c - GCC (C) 中的编译器标志
- reactjs - 找不到 TypeScript 常量字符串
- google-sheets - 使用 Miso 从 Google 表格中读取数据
- r - 使用库(dplyr),过滤器()通过单列中的多个条件对data.frame()中的行进行子集
- javascript - 将 id 从一个函数传递给事件侦听器函数以确认删除操作
- mysql - MySQL 使用准备好的语句插入/更新包含点类型的行
- redis - 如何在 Redis 中查找字符串
- python - 根据 numpy 数组评估函数
- reactjs - 建筑的未定义符号,反应原生 cocoapod 问题
- javascript - onmouseover 事件不播放声音的奇怪问题