c++ - c ++在变量中读取逗号分隔的文件
问题描述
我在文本文件中有带有逗号分隔值的字符串,我正在读取不同变量中的逗号分隔值,如下所示
ifstream file("example.txt");
int age, count;
char name[50]="\0";
char degree[50] = "\0";
while (file.getline(name, 50, ','))
{
file >> age;
file >> count;
file >> degree;
cout << name << age << count<<degree <<endl;
}
它为 and 赋值name
,age
但不为count
and赋值degree
。谁能指导我做错了什么?逗号分隔的字符串如下。
waqar ahmed,17,5,bscs
usman ahmed,17,6,mscs
解决方案
推荐阅读
- graphql - 如何分离模式和解析器并合并它们 apollo-server-express
- android - getAccountsByType("com.google") 无法为 minSdkVersion 21 和 targetSdkVersion 27 列出我的 Google 帐户
- apache - Apache2 模块 Filebeat
- java - 什么算法用于转换 ArrayList
到 LinkedHashSet 在 JRE - android - 在移动设备中,不同的应用程序能否响应浏览器号召性用语并直接打开?
- ruby-on-rails - 如何添加额外数据以加入 factory_bot 工厂中的表
- php - SSL 例程:tls_process_server_certificate:certificate verify failed 无法启用加密
- java - 组合框更改 JTable
- java - 休眠与 mysql 覆盖 pk
- node.js - 如何使用 nginx 将我的域连接到我的节点应用程序