小编mun*_*ish的帖子

原始类型的+运算符是否重载?

已经重载的运算符<<,>>,=等多次使用.

我想到的一个例子是当我们添加字符串时说:

string name = string("munish")+"kumar";

+运算符在字符串类中重载.

但是当我们添加像1 + 2这样的数字时(似乎不像是重载的操作员调用)

我只是想知道编译器是如何进行二进制加法的.

如果编译器这么做的话,我不需要担心它,只是好奇的问题.

c++ operator-overloading

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

如何在bash脚本中使用expect

这是我在以下 bash脚本中使用的代码片段:

  for user_input in `awk '{print}' testfile_$$.txt`
    do
    ipaddress=`echo $user_input | cut -d';' -f 1`
    command="${config_mode}`echo $user_input | cut -d';' -f 2-`"
            ping -w 1 $ipaddress 1> /dev/null 2> $ERR_LOG_FILE 1> $LOG_FILE
    if [ $? -eq 0 ];then
            ssh "$USERNAME@$ipaddress" "$command"
                                                  >> $LOG_FILE


    fi
    done
Run Code Online (Sandbox Code Playgroud)

我如何使用expect在此脚本中自动执行ssh登录.

我很期待并开始测试它(它失败了):

#!/usr/bin/bash


set force_conservative 0  ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} …
Run Code Online (Sandbox Code Playgroud)

bash expect

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

使用Visual C++ 2008的std :: unordered_map未声明的标识符

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

int main()
{
    unordered_map< int, string > m;

    m[1] = "one";   
    m[2] = "two";
    m[4] = "four";
    m[3] = "three";
    m[2] = "TWO!";
    cout << m[2] << endl;

    m.clear();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在学习,无法弄明白.编译器抛出类型unordered_map未声明的错误.

我使用的是Visual C++ 2008 Express Edition.

c++ unordered-map visual-studio-2008

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

在Windows批处理中打印段落

以下代码可以很好地打印段落

@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
  'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
  for /f "skip=%skip% tokens=*" %%A in (
   'findstr /n "^" "%~f0"'
  ) do (
    set "line=%%A"
    setlocal enableDelayedExpansion
    echo(!line:*:=!
    endlocal
  )
)
type test.txt
exit /b

:::BeginText
This text will be exactly preserved with the following limitations:

  1) Each line will be terminated by CR LF even if original has only LF. …
Run Code Online (Sandbox Code Playgroud)

windows batch-file

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

如果输入的数字不是一个完美的正方形,找到最近的完美正方形?

#include <iostream>
#include <limits>
#include <cmath>

using namespace std;

int main()
{
    int number;
    cout << "Enter the number whose sqare root needs to be calculated";
    cin >> number;
    cout << "Square root of " << number << " is " << (int)sqrt((float)number)  << " OR " << sqrt((float)number) << endl;
    if( (int)sqrt((float)number) == sqrt((float)number) )
    cout << "The number is a perfect sqaure";
    else
    cout << "The number is not a perfect square";
    //To find the nearest perfect square …
Run Code Online (Sandbox Code Playgroud)

c++

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

设计模式的重要性?

我正在学习C++我不太了解这些东西,除了在大型项目中实际工作时编程设计模式是必要的.我希望它在某种程度上是正确的.

这是所有面向对象语言的共同点,还是我需要专门研究C++设计模式.

它对你有什么帮助.这对于学习C++程序员来说非常重要.

请建议

c++ design-patterns

3
推荐指数
1
解决办法
569
查看次数

左手操作数cout如何在这里传递?

#include <iostream>
#include <iomanip>
using namespace std;

ostream & currency(ostream & output)
{
    output << "RS ";
    return output;
}

int main()
{
    cout << currency  << 7864.5;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

 RS 7864.5
Run Code Online (Sandbox Code Playgroud)

我不明白这似乎是如何工作的,即只是函数的名称currency 用于调用函数.不应该是这样,currency(cout)但使用它给出输出.

 RS 1054DBCC7864.5
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
104
查看次数

课堂上的吸气剂和二传手

我正在尝试编写一个程序,考虑到我有一大堆对象(包括一些数据,如id,name等)我有一个显示菜单,如:

1)

display_menu()
{
    vector< CD > CDArray;
    //some statements to display
    switch(choice)
    {
        //case1 , case 2, ...
        case x;
            for(int i=0; i < CDArray.size(); i++)
                CDArray[i].printCD(); //printCD() is a method of class CD
        //default
    }
}
Run Code Online (Sandbox Code Playgroud)

但是如果向量/数组很大,这将导致很多函数调用开销,使其变慢.

2) 我应该将函数printCD()声明为内联或

3) 声明另一个对象来调用该函数并通过引用传递vector/array,如:

display_menu()
{
    vector< CD > CDArray; 
    CD obj; 
    //some statements to display
    switch(choice)
    {
        //case1 , case 2, ...
        case x;
            obj.printCD(CDArray); //CDArray is passed by reference
        //default
    }
}
Run Code Online (Sandbox Code Playgroud)

第三种方法有问题吗?

你会建议什么方法?

c++

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

我的笔记本电脑的向下箭头键?

我的笔记本电脑的向下箭头键非常松散,似乎不会持续很长时间.

是否有可能写入任何PROGRAMM(以任何语言,但特别是C++)帽子模拟的向下箭头key.say我由PROGRAMM使得当我按A,B,C上的键板它模拟向下箭头键.

如果没有,那么有没有可用的软件呢?

c++ windows api winapi

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

我如何从expect脚本中的文件读取数据

#! /bin/expect   
set timeout 20 
set user [lindex $argv 0] 
set password [lindex $argv 1] 
set prompt "$ "  ;# -- main activity   
proc dostuff { currenthost} {      
;# do something with currenthost      
send -- "ls -lrt\r"   return}   ;# -- start of task

set fd [open ./hostlist r] 
set hosts [read -nonewline $fd] 
close $fd 

foreach host [split $hosts "\n" ] {       
spawn /usr/bin/ssh $user@$host       
  while (1) {         
    expect { 
        "no)? " {            
        send -- "yes\r"        
    }                  
    "password: " { …
Run Code Online (Sandbox Code Playgroud)

linux expect

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