Segfault from hflip
Segfault from hflip
由于某种原因,当我运行此代码时,我会得到一个segfault。它的作用是从输入中读取PGM文件并水平翻转。
这是我认为是有问题的代码:
for (i = pixels.size()-1; i = 0; i--){ // this loop takes the final value of the original vector and puts it into the first spot in the new hflip vector, and continues onwards
flippy.push_back(pixels[i]);
}
cout << "P2" << endl << numColumns << " " << numRows << endl << "255" << endl;
while (p < pixTotal){
for (int z = 0; z < numRows; z++){
cout << flippy[p] << " ";
}
cout << endl;
p++;
}
你有
for(i = pixels.size() - 1; i = 0; i-)
中间应为
i> = 0
不是
i = 0
我假设向量pixels
代表矩阵中的每一行。然后,要翻转向量中的所有值,您只需使用std::reverse_copy
即可:
std::vector<uint8_t> flippy;
flippy.resize(pixels.size());
std::reverse_copy(pixels.begin(), pixels.end(), flippy.begin());
您需要为每一行执行此操作。然后,您可以在每个反向后输出每个翻转行,以使矢量" flippy"仅表示当前行。
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- std::async from std::async in windows xp
- std::is_reference from std::any
- std::time_point from and to std::string
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- std::chrono::time_point from std::string
- Visual accept std::string from std::byte iterator
- C++中链表的错误"Abort signal from abort(3) (sigabrt) "
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++ 中的"template <typename From, typename Tag> struct Alias;"是什么?
- from std::vector to adept::avector
- qt get child (Callout) from QChart
- Webassembly from Javascript
- Generate boost::uuids::uuid from boost::compute::detail::sha
- 什么是"Reading unbounded stream from standard input (Memory Management)"的例子
- Calling C++ dll from python
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- std::chrono 在从 main 或 from 类方法使用时给出不同的值
- Calling Python Script from Visual Studio C++ Solution
- Segfault from hflip