Error C2014; Visual Studio 2012
Error C2014; Visual Studio 2012
我找到了将字符串转换为pdu (septet to octet char)的代码
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
std::string toPDU(const std::string &original)
// Converts an ANSI string to PDU format
{
if (original.empty()) {
// Empty string -> nothing to do
return original;
}
std::string result;
// Reserve enough space to hold all characters
result.reserve((original.length() * 7 + 7) / 8);
// Variables for holding the current amount of bits to copy from the next character
size_t bitshift = 1, mask = 0x01;
unsigned char curr = original[0]; //->> ERROR !!!!!!!!!!!!!!!!!
for (size_t i = 1; i < original.length(); ++i) {
if (bitshift != 0) {
// If bitshift is 0, then curr will be 0, so in effect we should skip a character
// So only do the following when bitshift different from 0
// Add the low bits (using the mask) to the left of the current character
curr += (static_cast<unsigned char>(original[i]) & mask) << (8 - bitshift);
result += curr;
}
// Remember the remaining bits of this character so that we can add them later
curr = (original[i] & ~mask) >> bitshift;
// Cycle bitshift through 0-7 (could also be written as bitshift = (bitshift + 1) mod 8)
bitshift = (bitshift + 1) & 0x7;
// Set the mask to have all bitshift lower bits set
// e.g. bitshift = 3, then mask = 0x07
// bitshift = 5, then mask = 0x1F
// bitshift = 7, then mask = 0x7F
mask = (1 << bitshift) - 1;
}
result += curr;
return result;
}
std::string toHEX(const std::string &original)
// Converts a string to the hexadecimal representation of its characters
{
std::ostringstream os;
os << std::hex << std::uppercase;
for (size_t i = 0; i < original.length(); ++i) {
os << static_cast<unsigned int>(static_cast<unsigned char>(original[i])) << " ";
}
return os.str();
}
int main()
{
using namespace std;
cout << toHEX(toPDU("hellohello")) << endl;
return 0;
}
在visual studio 2012中得到这个错误:
错误C2014:预处理器命令必须以第一个非空格开始
我是c++的新手,有人能解释为什么会发生这个错误吗?谢谢。
这可能是"HTML编码出错"
original[0];
应为
original[0];
其他有&#
的地方也一样。
解码可以在这里找到:
http://www.ascii.cl/htmlcodes.htm相关文章:
- 使用Visual Studio 2012编译时,此代码会给我错误,但是使用代码块就可以了
- 在 Visual Studio 2012 中未命中断点
- C Visual Studio 2012 Express命令窗口怪异行为
- Visual Studio 2012静态图书馆与Visual Studio 2017
- C 11魔术静态在Visual Studio 2012中的解决方法
- 在 Visual Studio 2012 中使用 "= delete" 时出现编译器错误
- Visual Studio (2012) 更改 dll 以导出类和变量
- 资源窗口在其他系统上无法正常工作 (Visual Studio 2012)
- C++函数中的内存泄漏,Visual Studio 2012,链表
- 两个不同的标题GCC,Visual Studio 2012
- gdal201.dll在Visual Studio 2012上的计算机错误中缺少
- Visual Studio 2012中可用覆盖的列表
- Windows 10中的Visual Studio 2012:找不到或打开PDB文件
- 在 64 位 Windows 8 机器上使用 Visual Studio 2012 构建 opencv 的绝对解决方案
- 如何在 Visual Studio 2012 中禁用大括号完成
- 如何在Visual Studio 2012中使用sqlite
- GLFW 链接问题 Visual Studio 2012.
- 使用Visual Studio 2012针对Windows XP构建Boost 1.52库
- 特定于域的语言工具 Visual Studio 2012 输出C++
- 生产力 Microsoft Visual Studio 2012 的电源工具不起作用