Talk:C++ Programming/Q&A

(Redirected from C++ Programming/Q&A)
Latest comment: 9 months ago by 203.214.45.199 in topic the hello world example

Welcome to the C++ Programming questions and answers page.
Feel free to post any questions you have while learning to program in C++.
If you have questions about this book, post them on the C++ Programming content discussion page.
If you know the answer to a question, or you can improve any, go ahead and do it.
After a response is given and the information is missing in the book, please add it and delete the post.
(give at least 7 days after the reply, no archive is needed to be maintained of this page).
You may also be interested on the material regarding this subject at Wikiversity.


Ask a question! See that you are logged into Wikibooks



how to move a text up and down using keys? edit

how to move a text up and down using keys?

You have to intercept the pressing of the keys, see the book example on how to get input from the keyboard and adapt it to detect those key presses, if you don't know the code for a particular key, print it to the screen after you have read it. if you think the example on how to get the keyboard data is missing something please ask again, please do sign you posts txs --Panic 14:41, 7 January 2007 (UTC)Reply

string::find return type edit

Which one is right?

  • string::find() returns an int ? -- old version of C++ Programming/Code/IO/Streams/string; but the compiler I'm using today tells me "warning: comparison between signed and unsigned integer expressions".
  • string::find() returns a size_type ? -- SGI reference; but the compiler I'm using today keeps telling me "error: 'size_type' was not declared in this scope".
  • string::find() returns a size_t ? -- another C++ reference; this seems to compile -- on this ancient compiler I'm using today. But is it portable?

--DavidCary (talk) 02:32, 16 March 2009 (UTC)Reply

What compiler are you using? size_type is the correct one, by what is on the 2003 standard.
Use string::size_type return = yourstring.find( <what you need to find> ); and the "error: 'size_type' was not declared in this scope" should be solved. --Panic (talk) 19:06, 16 March 2009 (UTC)Reply
Ah, that makes sense. Now my compiler accepts it. So actually
  • string::find() returns a string::size_type
right? --DavidCary (talk) 04:04, 18 March 2009 (UTC)Reply
Well the correct terminology is that the type is size_type, the string:: bit is the namespace/scope were the compiler can find a definition for it, in general a type can be the same or different across several namespaces/scopes sharing the same keyword, in this case it also exists in other namespaces/scope (ie vector::size_type) and from your previous searches it seems that some time back it was a int.
For what is on the standard (2003) the size_type is implementation dependent and size_t will (with a high degree of certainty) be equal to size_type (but the standard doesn't commit to it and I couldn't find a clear reason why...) --Panic (talk) 04:44, 18 March 2009 (UTC)Reply
Thank you. OK, I've updated C++ Programming/Code/IO/Streams/string based on the new understanding you've given me. As always, feel free to improve that page, even if it means reverting my mis-guided edits. --DavidCary (talk) 13:58, 24 March 2009 (UTC)Reply

mathematical operations edit

a c++ programe that can display mathematical operations.

No major problem, the only difficulty would be the output but that depends only on how much it needed to conform with the standard notation. You could output a TeX formula and render it elsewhere. --Panic (talk) 19:50, 18 May 2009 (UTC)Reply

Ejecting optical drive edit

How to eject optical drive using c++ code on turbo c++ 3.0 compiler without using any windows library or header file?

Only possibility is to call another program that executes delete that task. That operation is dependant on the OS. --Panic (discusscontribs) 22:09, 28 April 2011 (UTC)Reply

MATALAB? edit

How does C++ compare with MATALAB? When should one use C++ instead of MATLAB? When is C++ superior to MATLAB? When is MATLAB superior to C++?

That is a bit like discussing what the differences are between oranges and apples, even more problematic since the analogy is even closer since both are fruits.
C++ is a programming language MATLAB is not even if it is scriptable the functions or objectives rarely are the same (MATLAB can be used to examine algorithms). Since they really can't be directly compared (unless we define a specific problem that can be addressed by both) the comparison has no meaning in generic terms, each does what it they are proposed to do. Also consider that MATLAB is a commercial product there is some fairly recent products that already replicate some functionalities of that software package in the case of programming languages there is no direct concurrency, there is only one C++ language even if some other languages can perform the same tasks they are ultimately completely distinct in use, capabilities and results (see the book section that compares C++ with similar languages if you need further info on that). --Panic (discusscontribs) 08:39, 1 June 2011 (UTC)Reply

c++ programming logical edit

A=9,B=9 why C=A!=B+1+(A==B) get the result C=0 ? — Preceding unsigned comment added by 111.118.129.179 (talkcontribs) some time before 09:43, 4 February 2012 (UTC)Reply

Go by steps and check operator resolution priority on the table. In any case doing such logic in a single operation like that is bad coding practice, you can extend it into several operations unless compiler optimization needs to be turned off, in that case you should provide an appropriate comment. --Panic (discusscontribs) 09:44, 4 February 2012 (UTC)Reply

Programming terms edit

hello there, I don't know anything about programming c++, but i ran on these words and would like to know what they are or how to get them: can you help pls?


  • - initial interface
  • - data loggin
  • - polling system
  • - object inspector
  • - gage component

thanks a lot —Preceding unsigned comment by Elzeinhasan (discusscontribs) added before 2:10, 9 April 2024 (UTC)

This have no specific relation to C++, even if they can be declared as terms used in programming. All depend on the context they are used so it would be mostly guessing to what they mean as listed above.
An interface can be many things but lets assume it refers to classes, in that case the initial interface may be indicating the parent class interface before derivation.
Data logging relates to keeping "data" for review (a log).
Polling system may be something like detecting if a system is active (for instance in dealing with threads) or in networks it can also be referring to deciding a priority by a vote (see distributed systems).
Object inspector is just like it states, you should learn more about Object Oriented Programming first.
The gage component can be so many things that I will not conjecture about it.
Programming is hard, it is not only understanding a language but knowing what can be done with it, understanding all the intrinsics of a language. Knowing the code is even less important that fully understanding the concepts behind how and why things are implemented as they are. If you understand those, every language will become very similar to you, as they ultimately share the same basic functional purpose. --Panic (discusscontribs) 19:11, 2 May 2012 (UTC)Reply

C++ edit

what's the difference between \n & endl;

The first is a legacy notation from many older languages including C, the latest (I guess you intended to refer to std::endl) behavior is mostly equivalent but has further uses (streams) and guarantees see for example what was answered here, provides a complete coverage of the issue. --Panic (discusscontribs) 23:32, 26 January 2015 (UTC)Reply

the hello world example edit

Hi guys,

I am trying to learn C++ using your book. But the hello world example is confusing!

Here is why:

- the use of "int" before "main" is explained much later than it should be;

- the explanation claims that the first line of the program contains a line ending in \n and then waxes lyrical about what this means but the first line of the example does not contain \n !

raj 203.214.45.199 (discuss) 05:03, 13 July 2023 (UTC)Reply

Return to "C++ Programming/Q&A" page.