[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Is C the only good thing about C++? C++ without using functions

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 27
Thread images: 1

File: CPlusPlus.jpg (36KB, 433x455px) Image search: [Google]
CPlusPlus.jpg
36KB, 433x455px
Is C the only good thing about C++?

C++ without using functions from C standard library
#include <iostream>
#include <string>
#include <iomanip>

int main(int argc, char *argv[])
{
std::string str;
str = "Hello World!";
int count = 10;
if (argc > 1) {
std::string strargv1 = std::string(argv[1]);
count = std::stoi(strargv1);
}
for (int i = 0; i < count; i++)
std::cout << std::setw(2) << i + 1 << ". " + str << std::endl;
return 0;
}


While in C
#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char *argv[])
{
int i, count = 10;
char str[] = "Hello World!";
if (argc > 1)
count = atoi(argv[1]);
for (i = 0; i < count; i++)
printf("%2d. %s\n", i + 1, str);
return 0;
}


What's good about C++ abstractions when it's more complicated and less readable than plain old C and you can't figure out what the compiler is doing?
>>
it's more powerful xDD
>>
C# is better than both.
>>
>>58142328
t. pajeet
>>
>>58142278
If all you're doing is absurdly simple console IO, then yes.
>>
using namespace std;
>>
>>58142345
t. old faggot
>>
>>58142328
>2016
>using a DESIGNATED language
>>
>Hello World comparison

it doesn't matter

your opinion and input on the subject matter are completely irrelevant as you know literally fuck-all about either language, and most likely programming in general
>>
>>58142278
C is for largely embedded systems nowadays
writing much of anything else is quite a bit more tedious

C++ is utilized in a much wider range, but for example web development it isn't any good for

>>58142328
C# is good as a back-end systems language, among other things
however the accompanying overhead of a framework and virtual machine don't always make it a good choice

tl;dr each language has its uses and trivial syntax length comparisons only show that you're a retarded clueless fizzbuzz engineer
>>
>Deliberately writing code like a retard to make an invalid point about the brevity of a language.

    std::string str;
str = "Hello World!";


    std::string str = "Hello World!";


        std::string strargv1 = std::string(argv[1]);
count = std::stoi(strargv1);


        std::string strargv1 = std::stoi(strargv1);


The only substantial difference that you didn't artificially introduce yourself is iostreams, which despite being verbose comes with memory safety guarantees printf doesn't have. Otherwise all you did was write the same thing twice while introducing a bunch of unnecessary temporary variables in the C++ side.
>>
>>58142606
>but for example web development it isn't any good for
Except C++ is literally the best language for the web.
>>
>>58142278
The c++ example is more readable though.
>>
>>58142278
#include <iostream>
#include <string>
#include <iomanip>

int main(int argc, char *argv[])
{
using namespace std;
string str = "Hello World!";
int count = 10;
if (argc > 1)
count = stoi(string(argv[1]));
for (int i = 0; i < count; i++)
cout << setw(2) << i + 1 << ". " + str << endl;
return 0;
}
>>
>>58142685
auto str = "hello world"
>>
>>58147078
that doesn't yield a std::string, unless you append s to the end (C++17 only?)
>>
>>58142278

So c++ has a stoi function but doesn't have a proper toString one? (no boost doesn't count).
>>
>>58147782
>(C++17 only?)
>?
this is partly why C++ is so horrible
>>
>>58147929
std::to_string()
>>
>>58142278
Wow this trivial example BTFOs C++ for good.
>>
Lambdas
>>
>>58147990
>C++ is horrible because it's still getting regular updates
kill yourself as soon as possible
>>
>>58148262

I knew about that, but it's only C++11 and later.
>>
>>58148688
yes and?
>>
>>58142278
#include <iomanip>
#include <iostream>
#include <sstream>

int main(int argc, char *argv[]) {
std::string str ("Hello World!");
int count;
if (argc == 1) {
count = 10;
} else if (argc == 2) {
std::istringstream iss (argv[1]);
iss >> count;
if (iss.fail () || !iss.eof ()) {
std::cerr << argv[1] << " is not an int OP" << std::endl;
return 1;
}
} else {
std::cerr << "usage: " << argv[0] << " [INT]" << std::endl;
return 1;
}
for (int i (0); i < count; i++) {
std::cout << i + 1 << '\t' << str << '\n';
}
std::cout.flush ();
return 0;
}
>>
#include <iostream>
#include <thread>
void hello()
{
std::cout<<"Hello Concurrent World\n";
}
int main()
{
std::thread t(hello);
t.join();
}


I look forward to your cross platform C version of the above, standard libs only.
>>
>>58149015
>standard libs only
That's never fair.
Thread posts: 27
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.