C++ code snippets

a = 5

b = ++a
// Incrementa a y asigna su valor a b
// a = 6 y b = 6

c = a++
// Asigna el valor de 'a' a 'c' e incrementa 'a'
// c = 6 y a = 7

b = b * 5
// b = 6 * 5 = 30

a = a * 2
// a = 7 * 2 = 14

Discussion

El detalle está en los incrementos, tendrías que quitarle los ++ a la variable a

Discussion

You can do that in python too, that's just naming convention. Remember __init__ etc.?

Discussion

C++ its the most readabla language

who is better?
print "hello"

or

std::cout << "Hello" << std::endl;

Discussion

Also I suppose to use std::string and not char

Discussion

int main () {
int b[1];

b[0] = 20;
b[1] = 30;
b[2] = 25;
b[3] = 23;

printf ("%d\t%d\t%d\t%d\n", b[0], b[1], b[2], b[3]);

return 0;
}

Discussion

How is that possible?

for (auto it = vec.begin(); it != vec.end(); ++it) std::cout << "\n" << it - vec.begin() << "\n" << vec.end()- vec.begin() << "\n" << (it != vec.end() )<< "\n" << *it;

Prints 6 6 1 2 and continues loop?

Discussion

vec.begin() + (vec.end()-vec.begin()) != vec.end()

Discussion

You need to add one line like:
int C::n;
in any part of the file in the global scope

Discussion

But it's easy to find that cases: For example, the output string stream operator. If you want to make it simple, you need to use a friend member (1), because making it a C class member would make the left hand side of the operator need to be a C class object, that it's counter intuitive. The function signature has to be:
ostringstream &operator<<(ostringstream &lhs, C &rhs);

Discussion

I have the next class :

class point{

        double x,y;

    public:

        point(double a=0. , double b=0.){ x = a; y = b; }

        point(const point &p){ x=p.x; y=p.y;}

        point operator =(const point &p)

        { x = p.x; y = p.y; return *this; }

};

Discussion

point s(r);
point u=s;

Discussion

strchr could be your friend here

Discussion

You can do something like this:

std::string s = "word";
char c = 'c';
if(s.find(c) != std::string::npos){
// Here you found the letter
}

Discussion

//Demonstration of variables
#include <iostream>
#include <string>

using namespace std;

static void showUsage(char** argv) {
cerr << "GNU area version 0.01-beta\n"
<< "Usage: area <width> <height>\n"
<< "Computes the area from width and height\n"
<< "\nUse -h to show help\n";
}

int main( int argc, char** argv) {
if ( argc < 3 ) {
showUsage(argv);
return 1;
}

unsigned short int Width = stoi(argv[1]);
unsigned short int Length = stoi(argv[2]);

// create an unsigned short and initialize with result
// of multiplying Width by Length
unsigned int Area = (Width * Length);

cout << "Area: " << Area << endl;
return 0;
}

Discussion

>tfw aliased ls to ls -l

Discussion

But some namespaces are really long, so you can use using in some context if you don't want to be reading ns1::ns2...::nsN in all your code. So for your test is OK, at least in my opinion :)

Discussion

You have to import all header, but you can use this:

typedef std::string mystring;

or, in C++11:

using mystring = std::string;

Discussion

Is

using std::string;
using std::cout;

acceptable?

Discussion

That's another way to proceed, if you use a library with lib::string, std::string will be the used

Discussion

That is even more close to python from ns import module

Discussion

If i want to overload the operator « from std::ostream
what is better , make it

friend

so it can access to a private member , or make an observer method for that member ?

Discussion

Use:a8bot translate In the input field ..

Discussion