【发布时间】:2011-07-13 00:49:03
【问题描述】:
我正在尝试使用 _tcstok 标记文件中的行。我可以对线路进行一次标记,但是当我再次尝试对其进行标记时,我会遇到访问冲突。我觉得这与实际访问值有关,而是与位置有关。不过我不知道还能怎么做。
谢谢,
戴夫
附言我正在使用 TCHAR 和 _tcstok,因为文件是 UTF-8。
这是我得到的错误:
Testing.exe 中 0x63e866b4 (msvcr90d.dll) 的第一次机会异常:0xC0000005:访问冲突读取位置 0x0000006c。
vector<TCHAR> TabDelimitedSource::getNext() {
// Returns the next document (a given cell) from the file(s)
TCHAR row[256]; // Return NULL if no more documents/rows
vector<TCHAR> document;
try{
//Read each line in the file, corresponding to and individual document
buff_reader->getline(row,10000);
}
catch (ifstream::failure e){
; // Ignore and fall through
}
if (_tcslen(row)>0){
this->current_row += 1;
vector<TCHAR> cells;
//Separate the line on tabs (id 'tab' document title 'tab' document body)
TCHAR * pch;
pch = _tcstok(row,"\t");
while (pch != NULL){
cells.push_back(*pch);
pch = _tcstok(NULL, "\t");
}
// Split the cell into individual words using the lucene analyzer
try{
//Separate the body by spaces
TCHAR original_document ;
original_document = (cells[column_holding_doc]);
try{
TCHAR * pc;
pc = _tcstok((char*)original_document," ");
while (pch != NULL){
document.push_back(*pc);
pc = _tcstok(NULL, "\t");
}
【问题讨论】:
-
你为什么要投到
char*而不是TCHAR*?另外,你把TCHAR当作TCHAR*对待,那肯定很糟糕。 -
我去掉了一些选角等。还是一样的问题。
-
显然不是。不用强制转换写出来,你应该就能找到错误了。
-
摆脱了 char* 转换并得到了这个错误:'_tcstok' : cannot convert parameter 1 from 'TCHAR' to 'char ' 从整数类型转换为指针类型需要 reinterpret_cast, C风格转换或函数风格转换。我不明白为什么它会要求一个字符,因为我到处都在使用 TCHARs
-
大卫:正确,这就是问题所在:-) 你不能把一个字符当作一个指针。我认为您的代码有很多问题,所以我不愿意提供建议,但是应该发生类似
TCHAR * original_document = ...的事情;但我认为即使是你的向量也不能满足你的要求......
标签: c++ visual-studio-2008 utf-8 access-violation