我有一个元组列表。是否可以在不使用 numpy、pandas 等的情况下从每个元组中获取一列?
lst = [('a','b','c'),
('d','e','f')]
Run Code Online (Sandbox Code Playgroud)
假设我想得到 'b','e',但是
lst[:][1]
Run Code Online (Sandbox Code Playgroud)
我明白了
('d'、'e'、'f')
我正在尝试从 Udacity 学习 C++。我需要澄清一下我的理解是否正确。所以代码如下。
井字游戏:
class Board
{//the class tracks the game and the winner
char positionsSelected[16];
char winner;
public:
//Constructor
Board();
int setPosition(int gridNumber, char user);
char* getPositions(void);
};
char* getPositions(void)
{//return all the positions on the board
return positionsSelected;
}
Run Code Online (Sandbox Code Playgroud)
如果你看一下,成员函数char* getPositions(void)是在类内部声明的。
我知道假设可能真的很糟糕,但这就是我的思考过程和问题
由于您基本上是在阅读一系列字符,这就是为什么它必须是char*.
为什么必须的参数getPositions(void)?这可以与空括号 () 相同吗?
如果函数原型是char* getPositions(),是否意味着它返回了指针?我可以假设返回值char*getPosition(void)指向char array(positionsSelected).
如果我的假设是错误的 3. 我可以放这样的东西吗
char* getPositions(void){
char* pointers;
pointers = positionSelected;
return pointers;
}
Run Code Online (Sandbox Code Playgroud)
任何建议或解释将不胜感激。
我正在将一个项目从 VS 2010 迁移到 VS2019。我的代码在 VS 2010 中运行良好,而在 VS2019 中对于相同的代码却出现错误。
#undef inline
#define inline __forceinline
..///
..///code
#undef inline
#define inline inline
Run Code Online (Sandbox Code Playgroud)
Error C1189 #error: The C++ Standard Library forbids macroizing the keyword "inline". Enable warning C4005 to find the forbidden define
我怎样才能消除这个错误。
我正在使用 C++11 及更高版本,我在问自己是否可以安全地获取数据类型所需的字节数,例如std::uint16_t发送长度不可知的协议。更精确的调用是否安全,sizeof(std::uint16_t)我可以假设这总是 2 吗?怎么样std::int16_t?
我不明白为什么,但vector<thread>.push_back()会产生错误。我尝试用 替换产生错误的行.emplace_back(),但我仍然收到此错误。
总的来说,我的代码试图根据输入显示哪些数字是素数。我确实知道并且已经测试过 splitString() 和 isPrime() 函数可以完美运行,只是我对 main() 的实现不正确并且在编译时会产生错误。
这是我的代码;
#include <iostream>
#include <string>
#include <cstdlib>
#include <thread>
#include <vector>
using namespace std;
bool isPrime(int number) {
int scan = number - 1;
while(scan > 1){
if(number % scan == 0){
return false;
}
scan = scan - 1;
}
return true;
}
vector<string> splitString(string String, string seperator){
vector<string> result;
size_t pos = 0;
string token;
while((pos = String.find(seperator)) != string::npos){
token = String.substr(0, pos);
result.push_back(token); …Run Code Online (Sandbox Code Playgroud) 我有一位老师/教授只喜欢在 main 下方而不是在它上方编写函数。我将如何重写它以编写 main.js 下面的函数?一直在下面教怎么做,我可以提前声明吗?如果是这样,它会是什么样子?
#include <iostream>
using namespace std;
/* Output
Enter 4 test score numbers
80 90 80 90
Average is 86.6667
Enter 4 test score numbers
70 80 -60 90
Bad Data
*/
bool input(double& test1, double& test2, double& test3, double& test4)
{
cout << "Enter 4 test score numbers" << endl;
cin >> test1;
cin >> test2;
cin >> test3;
cin >> test4;
if(test1 < 0 || test2 < 0 || test3 < 0 || test4 …Run Code Online (Sandbox Code Playgroud) 我试图通过使用继承来实现从父类派生的子类,但我不断收到此错误:
/tmp/ccThP1Yc.o: In function `Cat::Cat(double, int)':
Animal.cpp:(.text+0x11a): undefined reference to `vtable for Cat'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我正在使用继承自 Cat::Cat(double weight, int age):Animal(name) 'name' 是 Animal 的构造函数,我想将它重新用于 Cat,也可以使用其他方法来自猫的动物。
这是我的头文件:
#include <iostream>
#include <string>
#ifndef ANIMAL_H
#define ANIMAL_H
class Animal
{
public:
Animal(std::string name);
std::string get_name();
virtual double get_weight();
virtual int get_age();
protected:
std::string animalName;
};
class Cat: public Animal
{
public:
Cat(double weight, int age);
std::string get_name();
int get_age();
double get_weight();
protected:
std::string catType; //type of cat (i.e. …Run Code Online (Sandbox Code Playgroud) 我有一个简单的工作函数,可以创建一个表记录文件信息。
但是,printf以错误的顺序打印我的输出。我尝试使用fflush(stdout)刷新缓冲区,但它没有改变任何东西。
功能:
void printTable(char *libraryName)
{
printf("%-40s%-30s%-25s%-20s\n", "[File Name]", "[Creation Time]", "[Version]", "[Size]");
fflush(stdout);
printf("%-40s%-30d%-25d%-20f\n", libraryName, getCreationTime(libraryName), getVersion(libraryName), getSize(libraryName));
fflush(stdout);
}
Run Code Online (Sandbox Code Playgroud)
get 函数在单独的文件中定义并提供准确的输出。
编译后,输出如下所示:
[File Name] [Creation Time] [Version] [Size]
125 kB
Version: 1.0.0.0 [6-02-2020 03:32:21 PM] Objects.dll
Run Code Online (Sandbox Code Playgroud)
但它需要看起来像这样:
[File Name] [Creation Time] [Version] [Size]
Objects.dll [6-02-2020 03:32:21 PM] 1.0.0.0 125 kB
Run Code Online (Sandbox Code Playgroud)
我需要对我的 printf() 函数做什么才能获得正确的订单输出?我试过刷新缓冲区并重新排列函数的顺序。是否可以在不为每个函数编写单独的 printf() 语句的情况下以正确的顺序获得输出?
我正在尝试 dockerize 我的 NodeJs & Express API 。在我的 API 中,我使用https://www.npmjs.com/package/compile-run包来编译和运行 C、Cpp、Java、JavaScript(Node.js env)、Python 语言。该软件包需要在服务器上安装所有 5 个编译器(gcc、g++、nodejs、python3、javac)。如果任何编译器未命中,它就会抛出错误。
在我的本地(undockerized)中,API 在 windows 和 ubuntu 上都运行良好(因为我已经在它们上面安装了编译器)。
我正在尝试在我的 docker 映像上复制相同的内容。但我被困住了。
看看我的 Dockerfile:
FROM node:12
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm","start"]
Run Code Online (Sandbox Code Playgroud)
我认为 node-12 图像带有 gcc、g++、python3 和 nodejs(显然)。但问题在于java。我无法编译 java 代码。
所以我这样试过
FROM node:12
RUN apt-get -y install default-jre
# RUN java -version
RUN apt -y install default-jre
RUN apt install openjdk-11-jre-headless
RUN java -version
WORKDIR /app …Run Code Online (Sandbox Code Playgroud)