我试图push_back在C++中使用字符串向量.如何将单个字符推送到矢量?目前,我尝试过以下方面,但都没有成功:
码
string str(main_string[0]);
vector_string.push_back(str);
Run Code Online (Sandbox Code Playgroud)
码
string str;
strcpy(main_string[0], str.c_str());
vector_string.push_back(str);
Run Code Online (Sandbox Code Playgroud)
我们欢迎任何更多的建议/想法.
编辑:错误日志如下:
test_push.C: In function ‘void test_push(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::string)’:
test_push.C:50: error: no matching function for call to ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char&)’
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:220: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(typename _Alloc::rebind<_CharT>::other::size_type, _CharT, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/basic_string.tcc:213: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, …Run Code Online (Sandbox Code Playgroud) 我有一个整数数组:
int a[5]={5,21,456,1,3}
Run Code Online (Sandbox Code Playgroud)
我需要将这些数字存储到char数组中,以便char数组有这样的东西:
char *s="52145613";
Run Code Online (Sandbox Code Playgroud)
这有c中的库函数吗?
我是新的Windows驱动程序开发和微过滤器,我试图建立nullFilter使用命令行工具样本.所以我添加#pragma comment(lib, "FltMgr.lib")到.c文件并成功发出以下命令:
cl.exe /nologo /Fo../../bin\filter.obj /c filter.c /D _AMD64_
rc.exe /nologo /Fo../../bin\filter.res filter.rc
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试创建sys文件时:
link.exe /nologo /DRIVER:WDM /out:../../bin\filter.sys ../../bin\filter.obj ../../bin\filter.res
LINK : error LNK2001: unresolved external symbol NtProcessStartup
../../bin\filter.sys : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)
我正在使用VS2012 Express和WDM8.我的LIB环境变量是:
C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64;C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\km\x64;
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我错过了什么吗?
我想要做的是取一个指向的字符串argv[1]并将其复制到另一个数组,但我希望这个新数组是const.
有没有办法将数组声明为const并使用argv[1]同一行的内容初始化它?
我遇到的问题是我无法将其声明为const然后在下一行使用strcpy或某些此类函数复制字符串.那是无效的.
什么是最好的行动方案?
让我们以下代码:
int x;
int *p = &x;
int t[3];
Run Code Online (Sandbox Code Playgroud)
然后sizeof返回:
sizeof(x) -> 4
sizeof(p) -> 8
sizeof(t) -> 12
Run Code Online (Sandbox Code Playgroud)
我想这sizeof(t)是结果3 * sizeof(int).但是作为t指向他的第一个元素的指针,它的大小应该是sizeof(p).
为什么sizeof(t)返回代表数组的内存块的大小?
谢谢.
我试图在这个问题上帮助OP .
我发现下面的代码会导致分段错误,即使堆栈设置为2000 KB也是如此.
int main ()
{
int a[510000];
a[509999] = 1;
printf("%d", a[509999]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,数组是510000 x 4bytes = 2040000bytes.
使用ulimit命令将堆栈设置为2000 KB(2048000字节):
根据这些数字,应用程序有空间存储数组,但随机返回分段错误.
有任何想法吗?
我有一个处理信号的父进程SIGCHLD。如果我调用abort()子进程,SIGABRT则会在子进程中引发信号。
我的问题是,在子进程核心转储时,SIGCHLD是否会向父进程发送信号?
我对内存分配有点困惑.
我想用随机数填充数独结构,然后检查一个9个数字的框是否正确.
#define SUDOKU_SIZE 9
typedef struct
{
int grid[SUDOKU_SIZE][SUDOKU_SIZE];
} sudoku_t;
int main(int argc, char const *argv[]){
sudoku_t *s=malloc(sizeof s);
s->grid[0][0]=6;//manualy setting the value of the sudoku
...
s->grid[8][8]=7;
fill_sudoku_test(s);//fill s, a feasible Sudoku with random number
int k, l;
for(k=0;k<SUDOKU_SIZE;k+=3){
for(l=0;l<SUDOKU_SIZE;l+=3){
if(correct_box(s,k,l))//check if a box of 3 by 3 contains 9 differents numbers
printf("Box correct at position :%d and %d\n",k,l);
}
}
free(s);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
当我编译此代码时,我收到了一个核心转储错误.
如果有人得到解决方案,我很感兴趣
编辑
这是其他功能:
void fill_sudoku_test(sudoku_t *s){
int k, l;
time_t t; …Run Code Online (Sandbox Code Playgroud) 我在32位架构上使用C语言.
如果我使用array[-2147483635]为什么C将其转换为array[13]?
-2147483635 在Two的补充是 10000000000000000000000000001101b
是否需要左位并将其转换为0以便它变为
00000000000000000000000000001101b,即13???
我认为它不适合size_t.因为size_t翻译-2147483635成4294967264.
我昨晚花了很多时间调试这段代码.我有两个数据文本文件,都包含18000个字符.我想将这些18000分成两个子串,每个子串100个,这使得180次迭代.
棘手的是,在前180次迭代中,两个子串的大小都很好.在18次迭代之后,子串的大小为0.
两个文件都正确打开.我可以打印它们等等.我尝试以我能想到的所有可能方式分配子字符串,但到目前为止找不到解决方案.
int main(int argc, char const *argv[]) {
//Ive loaded two files into two strings buff1 and buff2 both size of 18000 chars
//It works fine with small data example, I dunno why but eventually I have work with much more bigger data set
//Id like to divide them into 100 char long pieces and do some stuff with that
char *substrA; //substring for buff1
char *substrB; //substring for buff2
substrA = malloc((wlen+1)*sizeof(char)); //word length wlen=100
substrA = …Run Code Online (Sandbox Code Playgroud)