小编Joh*_*now的帖子

检查输入是否是C++中的数字或字符串

我写了下面的代码来检查输入(answer3)是一个数字还是字符串,如果它不是一个数字,它应该返回"仅输入数字",但它返回相同的数字.请建议我一个解决方案.

#include <iostream>
#include <string>
#include <typeinfo>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

using namespace std; 
int main ()
{

string ques1= "Client's Name :";
string ques2 = "Client's Address :";
string ques3 = "Mobile Number :";

char answer1 [80];
string answer2;
int answer3;

     cout<<ques1<<endl;    
     cin>>answer1;      

     cout<<ques2<<endl;    
     cin>>answer2; 

     cout<<ques3<<endl;
     cin>>answer3;

       if (isdigit(answer3))
       {
              cout<<"Correct"<<endl;     

              }

        else
        {
          cout<<"Enter Numbers Only"<<endl;  

            }

 system("pause>null");
 return 0;  

}
Run Code Online (Sandbox Code Playgroud)

c++ string integer user-input string-conversion

8
推荐指数
2
解决办法
6万
查看次数

您是否需要为AWS EC2中的安全组付费?

我最近有一个终止的EC2实例,除默认安全组(不允许删除)外,我已删除了所有内容。注意:我已删除所有入站规则和出站规则。我的帐单仍然反映按小时计费的EC2收费。我是否需要担心删除此安全组?

amazon-ec2

7
推荐指数
1
解决办法
6043
查看次数

Python 3 - TypeError:需要类似字节的对象,而不是'str'

我正在研究Udacity的一个教训,并且在尝试查看此站点的结果是返回true还是false时遇到了一些问题.我使用下面的代码获得TypeError.

   from urllib.request import urlopen
    #check text for curse words  
    def check_profanity():
        f = urlopen("http://www.wdylike.appspot.com/?q=shit")
        output = f.read()
        f.close()
        print(output)
        if "b'true'" in output:
            print("There is a profane word in the document")

    check_profanity()
Run Code Online (Sandbox Code Playgroud)

输出打印b'true',我不确定'b'来自哪里.

urllib unicode-string python-3.x

6
推荐指数
1
解决办法
9252
查看次数

错误:在项目同步之前无法运行配置

我正在使用 PyCharm 和 Bazel 插件。当尝试设置命令来运行我的程序时,有一条消息说

错误:在项目同步之前无法运行配置。

忽略该消息并尝试运行当然会导致崩溃。我尝试运行 file>>synchronize 但这似乎没有效果。如何同步我的项目?

plugins pycharm bazel

5
推荐指数
1
解决办法
1769
查看次数

Ts-Jest Typescript 诊断:错误 TS2307:找不到模块

我在一个包含 js 和 ts 文件的 vue 项目中使用 ts-jest。该项目使用该@字符进行导入到目录的相对映射src/renderer/。TS 因找不到模块而发出警告。我可以忽略警告并通过执行以下操作来运行测试:

  globals: {
    'ts-jest': {
      /* Fails on mapped import syntax without this.*/
      diagnostics: {
        ignoreCodes: ['2307'],
      },
    },
  },
Run Code Online (Sandbox Code Playgroud)

但我希望导入按预期运行。

开玩笑的配置文件

module.exports = {
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'vue'],
  transform: {
    '^.+\\.js$': '<rootDir>/node_modules/babel-jest',
    '.*\\.(vue)$': 'vue-jest',
    '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    '^.+\\.tsx?$': 'ts-jest',
  },
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/renderer/$1',
    '^vue$': 'vue/dist/vue.common.js',
  },
  roots: ['<rootDir>', '<rootDir>/src/renderer'],
  modulePaths: ['<rootDir>'],
  setupFiles: ['<rootDir>/vue-test-setup.ts'],
  snapshotSerializers: ['jest-serializer-vue'],
  testMatch: ['**/test/**/*.spec.(js|jsx|ts|tsx)|**/__test__/*.(js|jsx|ts|tsx)'],
  transformIgnorePatterns: ['<rootDir>/node_modules/?!(vue-timers)'],
  globals: {
    'ts-jest': {
      /* …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js ts-jest

5
推荐指数
0
解决办法
2819
查看次数

gRPC python发送图像+元数据

我需要将图像(numpy数组)、有关图像的附加元信息(如高度、宽度等)从 pythongrpc客户端传递到 pythongrpc服务器。

我需要运行这个方法。

import numpy as np 

def predict(img, w, h):
    # some operations
    return img.shape[2], np.mean(img)
Run Code Online (Sandbox Code Playgroud)

我查看了文档,但 protobuf 中没有兼容的numpy数组数据类型。

https://developers.google.com/protocol-buffers/docs/proto3

image_procedure.proto

syntax = "proto3";

// input image, width, height
message Image {
    image_type image = 1;
    int32 width = 2;
    int32 height = 3;
}

// output prediction

message Prediction {
    int32 channel = 4;
    float mean = 5;
}

// service
service ImageProcedure {
    rpc ImageMeanWH(Image) returns (Prediction) {} …
Run Code Online (Sandbox Code Playgroud)

python grpc

5
推荐指数
1
解决办法
6354
查看次数

Activity 的状态栏颜色无缘无故地不同

我创建了一个新活动,由于某种原因,当使用它时,它在状态栏中使用不同的颜色。奇怪的是,在“设计”预览中它呈现了正确的颜色。

下面是两张屏幕截图,较深的颜色是正确的颜色。

不正确 在此输入图像描述 正确的 在此输入图像描述

主题与其他 .xml 布局相同,因此我很难真正找出此错误的来源。下面是布局的代码:

活动菜单.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.brewguide.android.coffeebrewguide.MenuActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            />

    </android.support.design.widget.AppBarLayout>

<LinearLayout
    android:id="@+id/myfragment"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我不确定还需要包含哪些其他代码来诊断此问题。


编辑:

样式.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="DescriptionTextView">
    <item name="android:textColor">@color/colorPrimaryDark</item>
    <item name="android:background">@color/mainBackground</item>
</style>

<!--style for the …
Run Code Online (Sandbox Code Playgroud)

xml android statusbar

4
推荐指数
1
解决办法
2102
查看次数

Auth0 gradle依赖性错误

我正在尝试在我的项目中使用Auth0,当我尝试将其包含在build.gradle文件中时,我收到错误.我尝试添加以下内容:

compile 'com.auth0.android:auth0:1.10.0'

compile 'com.auth0.android:auth0:1.+'

我收到以下错误:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
Run Code Online (Sandbox Code Playgroud)

我跑了gradlew build --stacktrace,得到了这个:

14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:processDebugManifest'.
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Manifest merger failed with multiple errors, see logs
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
14:31:51.285 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
14:31:51.285 [LIFECYCLE] [org.gradle.internal.buildevents.BuildResultLogger]
14:31:51.286 [LIFECYCLE] …
Run Code Online (Sandbox Code Playgroud)

authentication android gradle

2
推荐指数
1
解决办法
639
查看次数

rand() 在每次函数调用时产生相同的结果(使用 srand(time(0))

我有一个类的成员函数,它应该生成一个范围内的随机数。为此,我使用 rand() 函数。该函数生成一个随机数,如下所示:

    unsigned seed;
    seed = time(0);
    srand(seed);
    std::cout << "Random Number: "<< rand() << std::endl;
Run Code Online (Sandbox Code Playgroud)

该函数在两个不同的对象上调用。结果是:

Random Number: 1321638448
Random Number: 1321638448
Run Code Online (Sandbox Code Playgroud)

每次我调用它时都是一致的。我究竟做错了什么?

c++ random

2
推荐指数
1
解决办法
3531
查看次数