【发布时间】:2014-01-07 02:17:59
【问题描述】:
我尝试在 C++ 中捕获一个输入 char* 的字符串 这是我的代码
void DBManager::printMatched(char* line, char* fileName)
{
line = strtok(line,"Show");
char* teamAName = strtok(line," ");
char* teamACity = strtok(NULL,"-");
char* teamBName = strtok(NULL," ");
char* teamBCity = strtok(NULL,"\n");
}
这是行内的文字 "显示 abcde fghij - klmnop qrstu"
这是可变数据:
teamAName = abcde
teamACity = fghij
teamBName = klmnop
teamBCity = qrs
如何修复我需要切入行中的 teamBCity。
我在 Linux 系统上工作。
【问题讨论】:
-
看起来问题出在调用例程中。
printMatched()怎么叫? -
当我调用函数时,行的末尾有 \n 但在 line = strtok(line,"Show"); \n 已关闭..
-
请显示使用
printMatched()并打印teamBCity的代码。我怀疑问题在于line的参数是如何生成的,或者您的打印teamBCity是如何产生的。
标签: c++ c text substring strtok