我正在尝试使用这样的strstr函数:
const char * pInicio = strstr(origem, chave);
if (pInicio != NULL) ...
与预期相反,当我执行“if”测试时,编译器会抛出访问位置违例异常。每当我尝试从字符串中获取一些不存在的关键词时,就会发生这种情况。
调用堆栈是:
ntdll.dll!779315de()
[Os quadros abaixo podem estar incorretos e/ou ausentes, nenhum símbolo foi carregado para ntdll.dll]
ntdll.dll!779315de()
ntdll.dll!7792014e()
> msvcr100d.dll!_output_l(_iobuf * stream, const char * format, localeinfo_struct * plocinfo, char * argptr) Linha 2361 + 0xa bytes C++
cccccccc()
输出结果为:
Exceção de primeira chance em 0x0f8620a7 (msvcr100d.dll) no TestesApp.exe: 0xC0000005: Violação de acesso ao ler o local 0x00000001.
Exceção sem-tratamento em 0x779315de no TestesApp.exe: 0xC0000005: Violação de acesso ao ler o local 0x00000001.
在异常之前,变量值为:
链接器命令行是:
/OUT:"C:\Users\Leandro\documents\visual studio 2010\Projects\TestesApp\Debug\TestesApp.exe" /INCREMENTAL /NOLOGO "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\TestesApp.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Leandro\documents\visual studio 2010\Projects\TestesApp\Debug\TestesApp.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:\Users\Leandro\documents\visual studio 2010\Projects\TestesApp\Debug\TestesApp.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
c / c ++命令行也是
/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\TestesApp.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue
在此之后,我尝试测试指针是否为null。 那是我现在的问题,如何解决这个问题?
祝你好运!
答案 0 :(得分:2)
无法复制您的错误。这是我试过的:
int main( int argc, char **argv )
{
char * chave = "$GNGSA";
const char * origem = "$GPRMC,000651.082,V,,,,,,,191210,,,N*4F $GPGGA,000652.091,,,,,0,00,,,M,0.0,M,,0000*5F $GPGSA,A,1,,,,,,,,,,,,,,,*1E";
const char * pInicio = strstr(origem, chave);
if (pInicio != NULL)
{
printf("found it\n");
}
return 0;
}
这在Visual Studio 2010中编译并运行时没有错误。顺便说一句,它找不到匹配项。我愿意接受如何调整它以创建错误的说明。
- 编辑 -
将编译器命令行设置为:/ ZI / nologo / W3 / WX- / Od / Oy- / D“WIN32”/ D“_DEBUG”/ D“_CONSOLE”/ D“_UNICODE”/ D“UNICODE”/ Gm / EHsc / RTC1 / GS / fp:precise / Zc:wchar_t / Zc:forScope /Fp"Debug\odt.pch“/ Fa”Debug \“/ Fo”Debug \“/ Fd”Debägc100.pdb“/ Gd / analyze- / errorReport:queue
链接器命令行:/OUT:"E:\code\odt\Debug\odt.exe“/ INCREMENTAL / NOLOGO”kernel32.lib“”user32.lib“”gdi32.lib“”winspool.lib“”comdlg32 .lib“”advapi32.lib“”shell32.lib“”ole32.lib“”oleaut32.lib“”uuid.lib“”odbc32.lib“”odbccp32.lib“/ MANIFEST /ManifestFile:"Debug\odt.exe。 intermediate.manifest“/ ALLOWISOLATION / MANIFESTUAC:”level ='asInvoker'uiAccess ='false'“/ DEBUG /PDB:"E:\code\odt\Debug\odt.pdb”/ SUBSYSTEM:CONSOLE / PGD:“E: \ code \ odt \ Debug \ odt.pgd“/ TLBID:1 / DYNAMICBASE / NXCOMPAT / MACHINE:X86 / ERRORREPORT:QUEUE
即使两个命令行基本相同,我仍然没有收到错误。我不知道该说些什么,抱歉。