#code review, just making sure its correct (beginner)

35 messages · Page 1 of 1 (latest)

stiff epoch
#

no, std::cin is used to read in data

#

so, using a string literal there makes no sense

#

using namespace std is also generally not the best practice

#

also, prefer newline characters over std::endl

uneven quartz
#

Something like this would be better

#

Notes:

1- Using namespace std tends to bad practice, better to get accustomed with std:: prefix.

2- Cin is for Console input stream, or just reading from the console, using the insertion operator ">>" makes so you "save" the stream data in a variable.

3- std::endl at the last line is to jump to the next line.

frosty valve
#

also doesent std::enl flush the buffer

stiff epoch
frosty valve
#

alright thanks.

#

but fr c++ datatypes are bloated

stiff epoch
#

why?

frosty valve
#

std::string

#

string should just be

#

a

#

common datatype token

#

Str

#

is what ppl use

#

i should be able to just declare strings the same way as intergers, booleans, everything else.

stiff epoch
#

you mean it should be a primitive type? well, no it shouldn't

#

if you understand how memory layout works like you'd know why it is the way it is

#

also that has nothing to do with "being bloated"

#

besides, std::string is required to implement small string optmization, so if anything it is the opposite of that

gleaming scarab
frosty valve
#

no

#

string should be built in

gleaming scarab
frosty valve
#

no

frosty valve
#

like

#

string

#

or

#

library::string

gleaming scarab
#

No, it doesn't make sense. You shouldn't be forced to use the library:: prefix everywhere just to use a string. C++ gives you a choice. If you want to use the std implementation in your cpp file, you write "using std::string", if you want to use the library implementation, you write "using library::string". If you prefer clarity, you use "std::" or "library::" prefix every time. That's one of the key differences between C++ and other languages - it gives you a choice instead of forcing solutions.

keen thicket
#

i have a 6k program that is entirely made with using namespace std and it works like a charm, yo can keep using