看起来我遇到意外的溢出,我不明白为什么会发生这种情况(让我感到沮丧):
这些都是使用MinGW编译的。我相信这可能是由于BSD和Windows之间的文件类型不同,因为我注意到如果我从Windows操作系统中复制numbers.txt,我会收到类似的错误。
Mac Shell: Downloads/>$ rm numbers.txt
# Downloaded new numbers.txt file from windows.
Mac Shell: Downloads/>$ ./Project1
Raw output:
-----------
Segmentation fault: 11
Mac Shell: Downloads/>$
void do_file_magic(string file){
string line, replace = "", numeral, dump = "", temp;
ifstream source ("numbers.txt");
if (!source.is_open()) {
die_a_clean_death("Unable to open source file:", file);
};
// Display output to console:
sep("Raw output:");
// read source file and output vowels to destination file.
while ( getline(source, line) || true) {
dump = dump + replace;
if ( line[0] != ' ') {
temp = num2string(roman2num(line));
line = remove_whitespace(line);
replace = line + string(17-line.size(), ' ') + temp + "\n";
// If you read this then you noticed that there was some shenagins going on.
} else {
numeral = num2roman(string2num(line));
line = remove_whitespace(line);
replace = numeral + string(17 - numeral.size(), ' ') + line + "\n";
};
if(source.eof()) {
break;
}
};
printf("file dump: \n%s", dump.c_str());
// Close the files
source.close();
// open the file in output mode nuking everything from orbit.
// (Its the only way to be sure)
ofstream destination("numbers.txt");
if (!destination.is_open()) {
die_a_clean_death("Unable to open destination file:", file);
};
// Just dump a variable to the file.
destination << dump << "\n";
destination.close();
};
有人可以帮我理解我在哪里出错吗?
答案 0 :(得分:2)
可能会有更多问题,但我发现的第一个问题是:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
at read1.TwoWaySerialComm.connect(TwoWaySerialComm.java:21)
at read1.TwoWaySerialComm.main(TwoWaySerialComm.java:108)
如果对while ( getline(source, line) || true) {
...
if ( line[0] != ' ') ...
的调用失败,getline
将为空,因此line
超出范围。