有没有人有一段代码,不windows.h用于在while循环中检查按键.基本上这个代码,但不必使用windows.h它.我想在Linux和Windows上使用它.
#include <windows.h>
#include <iostream>
int main()
{
bool exit = false;
while(exit == false)
{
if (GetAsyncKeyState(VK_ESCAPE))
{
exit = true;
}
std::cout<<"press esc to exit! "<<std::endl;
}
std::cout<<"exited: "<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在本教程之后,我得到以下错误,其中y = 1; 我正在使用Netbeans 6.5 for Python.谢谢
y=1
^
Run Code Online (Sandbox Code Playgroud)
SyntaxError:第8行:3不匹配的输入''期待DEDENT(temperatureconverter.py,第8行)
以下是python代码,格式化我感谢.
__author__="n"
__date__ ="$Jan 9, 2011 3:03:39 AM$"
def temp():
print "Welcome to the NetBeans Temperature Converter."
y=1
n=0
z=input("Press 1 to convert Fahrenheit to Celsius, 2 to convert Celsius to Fahrenheit, or 3 to quit:")
if z!=1 and z!=2 and z!=3:
e=input("Invalid input, try again?(y or n)")
if e==1:
t=''
temp()
if e==0:
t="Thank you for using the NetBeans Temperature Converter."
print "Celsius Fahrenheit" # This is …Run Code Online (Sandbox Code Playgroud) 我有以下代码使用标志编译GCC,-msse4但问题是pop计数只获得转换__m128i类型的最后四个8位.基本上我想要的是计算__m128i类型内的所有16个数字,但我不确定创建变量后要进行的内部函数调用popA.不知何故popA必须转换为包含所有128位信息的整数?我想这些_mm_cvtsi128_si64并且使用了一些shuffle几个操作,但我的操作系统是32位.是否只有shuffle方法并使用_mm_cvtsi128_si32?
编辑:如果shuffle方法是唯一的选项,我需要帮助实现它为我的32位操作系统,请.
继承人的代码.
#include <stdio.h>
#include <smmintrin.h>
#include <emmintrin.h>
int main(void)
{
int A = 1;
__m128i popA = _mm_set_epi8( A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A);
unsigned int integer = _mm_cvtsi128_si32(popA);
//long long LONG = _mm_cvtsi128_si64(popA);//my OS is 32-bits so no luck here
printf("integer = %d\n", integer);
int pop = _mm_popcnt_u32(integer);
//int popLONG = _mm_popcnt_u64(LONG); …Run Code Online (Sandbox Code Playgroud) 我想要做的是在下面的代码中打印整数0到5,但我得到的只是迭代器的地址?
def main():
l = []
for i in range(0,5):
l.append(i)
it = iter(l)
for i in range(0,5):
print it
it.next()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud) 我收到以下错误:
preprocessor_directives.cpp|15|error: expected unqualified-id before '<' token|
preprocessor_directives.cpp|26|error: expected `;' before "int"|
||=== Build finished: 2 errors, 0 warnings ===|
Run Code Online (Sandbox Code Playgroud)
#include <iostream>
using namespace std;
// Avoid. Using #define for constants
#define MY_CONST1 1000
// Use. Equivalent constant definition
const int MY_CONST2 = 2000;
// Avoid. Using #define for function like macros
#define SQR1(x) (x*x)
// Use. Equivalent function definition
inline template <typename T>
T SQR2 ( T a ) {
return a*a;
}
// Writing #define in multiple lines …Run Code Online (Sandbox Code Playgroud) 下面的代码转换为std::stringto int,问题在于它无法从真正的整数或只是随机字符串中辨别出来.有没有系统的方法来处理这样的问题?
#include <cstring>
#include <iostream>
#include <sstream>
int main()
{
std::string str = "H";
int int_value;
std::istringstream ss(str);
ss >> int_value;
std::cout<<int_value<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我喜欢的解决方案,因为它非常小巧而优雅!它不适用于负数,但我只需要积极的数字.
#include <cstring>
#include <iostream>
#include <sstream>
int main()
{
std::string str = "2147483647";
int int_value;
std::istringstream ss(str);
if (ss >> int_value)
std::cout << "Hooray!" << std::endl;
std::cout<<int_value<<std::endl;
str = "-2147483648";
std::istringstream negative_ss(str);
if (ss >> int_value)
std::cout << "Hooray!" << std::endl;
std::cout<<int_value<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 基本上,问题与 x86 汇编器有关,其中您有一个数字想要设置为零或使用. 如果你的数字带有负一,你会得到数字本身,但如果你的数字为零,你会得到零。andandand
现在,我在 SSE 内在函数方面遇到的问题是,二进制中的浮点数与双精度数不同(或者也许我错了)。无论如何,这是代码,我尝试使用各种浮点数来掩盖第二个和第三个数字(分别为 127.0f 和 99.0f),但没有运气。
#include <xmmintrin.h>
#include <stdio.h>
void print_4_bit_num(const char * label, __m128 var)
{
float *val = (float *) &var;
printf("%s: %f %f %f %f\n",
label, val[3], val[2], val[1], val[0]);
}
int main()
{
__m128 v1 = _mm_set_ps(1.0f, 127.0f, 99.0f, 1.0f);
__m128 v2 = _mm_set_ps(1.0f, 65535.0f, 127.0f, 0.0f);
__m128 v = _mm_and_ps(v1, v2);
print_4_bit_num("v1", v1);
print_4_bit_num("v2", v2);
print_4_bit_num("v ", v);
return 0; …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码将值插入boost unordered_multimap,但由于它没有编译,因此无效.为什么没有access []运算符?
insert()方法也不起作用?
#include <iostream>
#include <boost/unordered_map.hpp>
using namespace std;
int main()
{
typedef boost::unordered_multimap<
int,
boost::unordered_multimap<
int,
boost::unordered_multimap<int, int>
>
> unordered_map;
unordered_map _3d;
_3d[0][0][0] = 10;
_3d[0][0][0].insert(10);
cout << _3d[0][0][0] << endl;
}
Run Code Online (Sandbox Code Playgroud)
错误:
multimap.cpp ||在功能
'int main()':
multimap.cpp | 19 |错误:不对应的'operator[]'在'_3d[0]'
multimap.cpp | 21 |错误:不对应'operator[]'于'_3d[0]'
|| ===构建完成:2个错误,0个警告===
在Cygwin终端,我输入
$ gfortran -o threed_euler_fluxes_v3.exe threed_euler_fluxes_v3.f90
Run Code Online (Sandbox Code Playgroud)
我得到编译器错误
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.17-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我也试过像这样编译
$ gfortran -o threed_euler_fluxes_v3.exe threed_euler_fluxes_v3.f90 -shared
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行时,我得到一个错误,说它不是一个有效的Windows程序?
继承人完整的fortran代码.我删除了一些评论,以保持字数限制低于30k继承人原来的.
subroutine inviscid_roe(primL, primR, njk, num_flux)
implicit none
integer , parameter :: p2 = selected_real_kind(15) ! Double precision
!Input
real(p2), intent( in) :: primL(5), primR(5) ! Input: primitive variables
real(p2), intent( in) :: njk(3) ! Input: face normal vector
!Output
real(p2), intent(out) :: num_flux(5) ! Output: numerical flux …Run Code Online (Sandbox Code Playgroud) 我想创建一个delete_node函数,它将列表中位置的节点删除为第一个节点的计数.到目前为止,这是我的代码:
class node:
def __init__(self):
self.data = None # contains the data
self.next = None # contains the reference to the next node
class linked_list:
def __init__(self):
self.cur_node = None
def add_node(self, data):
new_node = node() # create a new node
new_node.data = data
new_node.next = self.cur_node # link the new node to the 'previous' node.
self.cur_node = new_node # set the current node to the new one.
def list_print(self):
node = ll.cur_node
while node:
print node.data
node = node.next …Run Code Online (Sandbox Code Playgroud) c++ ×5
python ×3
intrinsics ×2
sse ×2
boost ×1
counter ×1
cygwin ×1
exit ×1
fortran ×1
gcc ×1
gfortran ×1
integer ×1
iterator ×1
linked-list ×1
list ×1
map ×1
onkeypress ×1
population ×1
printing ×1
string ×1
typechecking ×1
while-loop ×1