我有一个步骤的示例程序,我想在我的应用程序上实现.我想将字符串上的int元素分别推送到向量中.我怎么能够?
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(){
string line = "1 2 3 4 5"; //includes spaces
stringstream lineStream(line);
vector<int> numbers; // how do I push_back the numbers (separately) here?
// in this example I know the size of my string but in my application I won't
}
Run Code Online (Sandbox Code Playgroud) 在阅读有关断言的一些文档时,我发现:
java -ea -dsa
Run Code Online (Sandbox Code Playgroud)
"通常会启用断言,但会禁用系统类中的断言."
哪个是系统类?
我想用up,down,left,right作为opengl + glut应用程序控件的一部分.我如何参考我的' keyboard'函数中的键(我传递给的那个glutKeyboardFunc)?
请考虑以下代码:
#include <stdio.h>
#include <ctype.h>
char* Mstrupr(char* szCad);
int main()
{
char szCadena[] = "This string should print well.";
printf("%s\n", Mstrupr(szCadena));
printf("%s\n", Mstrupr("This string should fail."));
return 0;
}
char* Mstrupr(char* szCad)
{
int i;
for (i=0; szCad[i]; i++)
szCad[i] = toupper(szCad[i]);
return szCad;
}
Run Code Online (Sandbox Code Playgroud)
第二次调用Mstrupr无法在linux上正确运行,因为它接收字符串作为文字(而不是字符数组).当在gdb上运行完整的程序时它也会失败,但是当断点被添加到main并且程序通过gdb的下一个命令运行时,第二个字符串被大写并打印.为什么?我相信这不应该,但我的导师坚持认为这是gdb设计的一部分.
对于我的操作系统课程,我的任务是通过系统调用(无 scanf 或 printf)实现 Unix 的 cat 命令。这是我到目前为止得到的:
(感谢回复已编辑)
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
main(void)
{
int fd1;
int fd2;
char *buffer1;
buffer1 = (char *) calloc(100, sizeof(char));
char *buffer2;
buffer2 = (char *)calloc(100, sizeof(char));
fd1 = open("input.in", O_RDONLY);
fd2 = open("input2.in", O_RDONLY);
while(eof1){ //<-lseek condition to add here
read (fd1, buffer1, /*how much to read here?*/ );
write(1, buffer1, sizeof(buffer1)-1);
}
while (eof2){
read (fd2,buffer2, /*how much to read here?*/); …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何在C++中对字符串进行标记?
伪代码:
Attributes[] = Split line(' ')
Run Code Online (Sandbox Code Playgroud)
怎么样?
我一直这样做:
char *pch;
pch = strtok(line," ");
while(pch!=NULL)
{
fputs ( pch, stdout );
}
Run Code Online (Sandbox Code Playgroud)
并获得一个非书面,卡住的退出文件.这有什么问题吗?好吧,事情甚至没有满足我的伪代码要求,但我对如何将令牌(作为char数组)索引到我的数组感到困惑,我想我应该写一个2-dim数组?
作为家庭作业,我正在实施Karatsuba的算法,并针对大整数的小学式O(n ^ 2)乘法算法进行基准测试.
我猜这里我唯一的选择是将数字带到它们的字节数组表示中,然后从那里开始工作.
好吧,我被困在这里...当使用*运算符时,我不知道如果数字溢出一个字节乘法或添加一个进位,我将如何检测/纠正.有任何想法吗?
public static BigInteger simpleMultiply(BigInteger x, BigInteger y){
//BigInteger result = x.multiply(y);
byte [] xByteArray = x.toByteArray();
byte [] yByteArray = y.toByteArray();
int resultSize = xByteArray.length*yByteArray.length;
byte [][] rowsAndColumns = new byte[resultSize][resultSize];
for (int i =0; i<xByteArray.length;i++)
for (int j=0; j<yByteArray.length;j++){
rowsAndColumns[i][j] = (byte )(xByteArray[i] * yByteArray[j]);
// how would I detect/handle carry or overflow here?
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 我想在MPI中运行Thimoty的Rolfe实现mergesort,但为了使它工作,我需要编译他提供的wallClock.c文件.
#include <time.h>
double wallClock(void)
{
struct timeval tv;
double current;
gettimeofday(&tv, NULL); // Omit the timezone struct
current = tv.tv_sec + 1.0e-06 * tv.tv_usec;
return current;
}
Run Code Online (Sandbox Code Playgroud)
编译时我收到以下错误:
wallClock.c:12: error: storage size of ‘tv’ isn’t known
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
顺便说一句,我改变了他#include <sys/time.h>对 #include <time.h>
它产生了以下错误
wallClock.c:15: error: ‘NULL’ undeclared (first use in this function)
wallClock.c:15: error: (Each undeclared identifier is reported only once
wallClock.c:15: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
我尝试包括stdlib.h(修复NULL未声明的)并得到更加模糊的错误.
我在64位Ubuntu 12.04机箱上成功安装了cuda 5的nvidia驱动程序和工具包(但不是样本).即使我以前跑过,样本也无法安装
$ sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
我似乎无法找到nvcc.我跑了
$ export LD_LIBRARY_PATH =/usr/local/cuda-5.0/lib:/usr/local/cuda-5.0/lib64: $ LD_LIBRARY_PATH
nvcc -v报告找不到编译器:
nvcc -V没有找到命令'nvcc',你的意思是:来自包'vlc-nox'命令'nvlc'(宇宙)nvcc:命令未找到
入门指南在这里没有多大帮助:http: //docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html
这里发生了什么?我是否需要安装gpu computing sdk示例才能获得nvcc?:/
c ×4
c++ ×2
java ×2
assertions ×1
biginteger ×1
bytearray ×1
cat ×1
cuda ×1
debugging ×1
gcc ×1
gdb ×1
glut ×1
nvcc ×1
opengl ×1
string ×1
stringstream ×1
system-calls ×1
unicode ×1
vector ×1