C++如何在txt文件中读入带空格的sring字符串后再读数字
答案:3 悬赏:20
解决时间 2021-03-05 05:29
- 提问者网友:雪舞兮
- 2021-03-04 22:51
C++如何在txt文件中读入带空格的sring字符串后再读数字
最佳答案
- 二级知识专家网友:封刀令
- 2021-03-04 23:52
使用标准库的getline函数读一行。
#include
#include
#include
int main()
{
std::ifstream fin("test.txt");
std::string s;
std::getline(fin, s);
int i, j;
fin >> i >> j;
fin.close();
std::cout << s << std::endl; //Engllish name jack
std::cout << i << std::endl; //100
std::cout << j << std::endl; //1
return 0;
}
#include
#include
#include
int main()
{
std::ifstream fin("test.txt");
std::string s;
std::getline(fin, s);
int i, j;
fin >> i >> j;
fin.close();
std::cout << s << std::endl; //Engllish name jack
std::cout << i << std::endl; //100
std::cout << j << std::endl; //1
return 0;
}
全部回答
- 1楼网友:骨子里都是戏
- 2021-03-05 01:41
用fgets函数试试,具体使用请百度fgets
- 2楼网友:蕴藏春秋
- 2021-03-05 00:50
建议全部读成字符串,然后自己把其中的本分字符串转成数字
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯