我写了一个控制台程序,如果我在 fp->kind 中给出一个空格,它就会崩溃。这是我的代码。
#include <iostream>
struct fish
{
char kind[40];
float lenght;
float weight;
};
int main()
{
using std::cout;
using std::cin;
fish* fp = new fish();
cout<<"enter the kind of fish: ";
cin>>fp->kind;
cout<<"\nenter the weight of the fish: ";
cin>>fp->weight;
cout<<"\nenter the lenght of the fish: ";
cin>>fp->lenght;
cout<<"\nKind: "<<fp->kind
<<"\nlenght: "<<fp->lenght
<<"\nweight: "<<(*fp).weight;
cin.get();
cin.get();
delete fp;
return 0;
}
如果我不给空间,它不会崩溃。
PS即时使用Visual Studio 2012。这是调试输出。
'Project1.exe' (Win32): Loaded 'C:\Users\Dark Vadar\Documents\Visual Studio 2012\Projects\Project1\Debug\Project1.exe'. Symbols loaded.
'Project1.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'Project1.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'Project1.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'Project1.exe' (Win32): Loaded 'C:\Windows\System32\msvcp110d.dll'. Symbols loaded.
'Project1.exe' (Win32): Loaded 'C:\Windows\System32\msvcr110d.dll'. Symbols loaded.
The program '[1848] Project1.exe' has exited with code 0 (0x0).