所以我想从文本文件中提取一行,并提取每行中的第一个字并保存在字符数组“op”中。我在处理第一个单词之前的空格时遇到了麻烦。文中的第一行是“真棒酱油”,第二行是“是”,第三行是“酷”,第四行是“是的好”。在单词yeah之前处理空格有困难。从getline中提取字符数组,不使用字符串
infile.open(“vec.txt”);
//define line pointer
char* line=new char[100];
char other[100];
char op[100];
int numofLines = 0;
int k = 0;
bool wordStart = false;
//get line
while (infile.getline(other,100))
{
int numofChar = k;
int numofOpChar = 0;
int r = 0;
int p = 0;
while (other[k] == ' ')
{
while (other[k] != ' ')
{
wordStart = true;
}
k++;
cout << k << endl;
}
if (wordStart = true)
{
do
{
op[numofOpChar] = other[numofChar];
numofChar++;
numofOpChar++;
}
while (other[numofChar] != ' ');
if (op[numofChar] != ' ')
{
cout << op << endl;
}
}
}
做什么? –
不,我希望操作码数组每次都包含第一个单词。 – ruchithelamp
德你用调试器通过代码?它出错了哪里? – pm100