Getline 直接到数组 C++,在一行中
getline directly to array c++, in one line
有没有办法直接将getline
存储到c char array
中。
目前,我正在做这样的事情...
istreams.getline(name, sizeof(name));
strcpy(names[i], name);
有没有办法只在一行中做到这一点,例如istreams.getline()
.
替换这两行
istreams.getline(name, sizeof(name));
strcpy(names[i], name);
对于这个
istreams.getline( names[i], sizeof(names[i]));
我想names
是一个二维字符数组。否则,如果names[i]
是一个指针,那么你必须使用其他值而不是表达式sizeof(names[i])
您也可以使用 std::vector<std::string>
作为字符串的容器。
例如
while ( std::getline( istreams, name ) ) v.push_back( name );
相关文章:
- C++找出覆盖同一行的数组
- 如何让字符数组在一行而不是多行中打印出来?
- 在 c++ 中将uint8_t数组转换为字符串以在一行中打印
- 在一行中初始化和引入数组向量的正确方法?
- 将上一行添加到 char* 数组中的 char* 常量
- 将 ifstream 文件和每一行读取到数组中
- 在 C++ 中搜索 2D 数组以查看一行/列是否与另一行/列相同
- 与 C++ 中一行中的用户输入数组元素相关的问题
- 将地址返回到 2D 数组中的一行值的函数
- C ++试图找到数组中每一行的最大值
- 如何在一行中从不同的变量(数据类型)创建一个字符数组?
- C++ ->尝试逐字阅读一行文本。如何使指针等效于用于存储输入的当前二维数组
- C++ 哪些列在 2 dim 数组中的每一行都有 1
- 按一行对2D数组进行排序
- 无法弄清楚为什么只从文件中读取一行矩阵以及为什么我无法将 2D 数组传递给函数
- 打印一行 2D 字符数组 (C++)
- 如何将.txt文件中的多维数组放入代码中,并一次打印一行
- C++ - 将数字表从文件读取到 2D 数组中(仅存储最后一行)
- 在同一行中读取混合输入(字符串/浮点数),并将其存储在数组中
- 如何在每一行数组C++中进行颜色更改