大约有 43,000 项符合查询结果(耗时:0.0238秒) [XML]
ifstream 线程安全读文件 - C/C++ - 清泛网 - 专注C/C++及内核技术
... case EOF:
return is;
default:
t += (char)c;
}
}
}
例子:
int main()
{
std::string path = "end_of_line_test.txt"
std::ifstream ifs(path.c_str());
if(!ifs) {
std::cout << "Failed to open the file." << std::endl;
...
c++11右值引用、std::move移动语义、std::forward完美转发的一些总结 - C/C...
...还能拷贝构造,保障代码安全。对于一些基本类型如int和char[10]等,使用std::move()仍然会发生拷贝,因为没有对应的移动构造函数。
对于完美转发而言,右值引用并非“天生神力”,只是c++11新引入了右值,因此为其新定下了引...
Java 调用外部进程 - 更多技术 - 清泛网 - 专注C/C++及内核技术
... while (c >= 0) {
builder.append((char) c);
c = inputStream.read();
}
} catch (IOException e) {
}
}
}.start();
}
}
Java 外部进程
Linux automake自动编译全攻略 - 脚本技术 - 清泛IT社区,为创新赋能!
...nclude <stdio.h>
#include "lib/calc.h"
int main(int argc, char** argv)
{
int sum = add(1, 2);
printf("sum:%d\n", sum);
r...
C语言面试那些事儿──一道指针与数组问题 - c++1y / stl - 清泛IT社区,为创新赋能!
首先看如下代码:
int main(int argc, char** argv)
{
int a[5] = {1,2,3,4,5};
int* ptr = (int*)(&a + 1);
printf("%d,%d\n", *(a+1), *(ptr-1));
return 0;
}复制代码这道题在很多所谓经典C语言面试题里是常见...
SHFileOperation 这个API函数怎么用起来结果飘忽不定? - c++1y / stl - 清...
...配符查找文件,核心代码如下:
WIN32_FIND_DATA FindFileData;
char szCurPath[MAX_PATH + 1] = { 0 };
GetCurrentDirectory(MAX_PATH, szCurPath);
CString findFileName;
findFileName.Format("%stest*.txt", szCurPath);
HANDLE hFind = ::FindFirstFile(findFileName, &FindFileData);
if...
sizeof、strlen简单总结 - C/C++ - 清泛IT论坛,有思想、有深度
sizeof strlen const char* p 4 字符串长度 std::string 4 字符串长度 "......" 字符串长度+1 ('\0') 字符串长度
Linux C/C++进程单实例互斥代码分享 - C/C++ - 清泛网 - 专注C/C++及内核技术
...xit(1);
}
}
// 锁定文件后,将该进程的pid写入文件
char buf[16] = {};
sprintf(buf, "%d", getpid());
ftruncate(fd, 0);
ret = write(fd, buf, strlen(buf));
if (ret < 0) {
printf("Write file failed, file: %s, error: %s\n", kPidFileName, strerror(errno));
close(fd);
...
【解决】double free or corruption (!prev) - C/C++ - 清泛网 - 专注C/C++及内核技术
...大小,在free的时候也会检测出来,报这个错误,如:
char* buf = malloc(5);
memcpy(buf, "123456", 6);
free(buf); //free时报此错误
实际项目中可能此类问题没法直观定位到,推荐使用gcc自带的 asan 检查内存错误。
asan 内存跟踪
libunwind:记录程序崩溃堆栈 - 开源 & Github - 清泛网 - 专注C/C++及内核技术
...all
记录堆栈的代码如下:
static void log_backtrace(void) {
char name[256];
unw_cursor_t cursor;
unw_context_t uc;
unw_word_t ip, sp, offp;
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
syslog(LOG_ERR, "--illegal memory access--");
while(unw_step(&cursor) > 0) {...