我在从xlsx文件复制的txt文件中读取空格时遇到问题



我从xlsx文件中复制了一些数字,并将它们粘贴到txt文件中。我想使用getline((函数通过在空白处停止来单独读取数字。我的问题是,尽管空白出现在txt文件上,但程序无法识别。我在这里做错了什么?提前感谢!

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include  <stdio.h>
using namespace std;
int i;
char ch;
void readtxtfiles();
string line, first_n, second_n, third_n, fourth_n, fifth_n, joker_n;
int main()
{
system("chcp 1253");
readtxtfiles();
}
void readtxtfiles()
{
ifstream jokerfiles("Joker_2015.txt");
string line;
//jokerfiles >> noskipws >> first_n>>second_n>>third_n>>fourth_n>>fifth_n;
for (i = 1; i <= 1; i++)
{
getline(jokerfiles, line);
stringstream ss(line);
getline(ss, first_n, ' ');
getline(ss, second_n, ' ');
cout << first_n << endl;
cout << second_n << endl;
}
} // added by user4581301

这是输入文件的链接https://filebin.net/e3404yceh41audys

从屏幕截图中看不出来,但你确定这些是空格而不是制表符吗?您可以尝试用't'替换getline中的' '

getline(ss, first_n,'t');

最新更新