How do you view cpp files in the Command Prompt?

Discussion in 'Scripting & Programming' started by Alex Wright, Sep 20, 2007.

  1. Alex Wright

    Alex Wright Megabyte Poster

    501
    9
    57
    Hi all,

    Today I started my computing degree course and discovered that the first topic that we'll be covering is programming concepts. The first language that we're going to learn is C++.

    Now to carry on the fine apprentice programmers tradition our tutor got us all to create a programme displaying the text "Hello World" in Visual Studio 2005. We will be given a copy of Visual Studio but not for another fortnight. With that in mind I decided to download a free source code editor called Notepad++. Since I got home I've used this application to practice the topics covered in todays lesson. I've saved a .cpp file named 'first attempt' to my desktop, and was wondering if it's possible to view the contents of this file using the Command Prompt?

    I look forward to your informative replies. :)

    Best regards,

    Alex
     
    Certifications: 70-680 Configuring Windows 7
    WIP: 70-642
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    CPP files are just text. So any text viewer/editor will do, including notepad and wordpad.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. Alex Wright

    Alex Wright Megabyte Poster

    501
    9
    57
    Hi hbroomhall,

    Thanks for the reply. I know that .cpp files are only text files, what I'm trying to do is check the programme I've written for any errors and I don't know how you do this from within Notepad++:

    http://notepad-plus.sourceforge.net/uk/site.htm

    In Visual Studio your programme won't run in the Command Line Interface if it has errors.

    Hope this makes sense.

    Cheers :)
     
    Certifications: 70-680 Configuring Windows 7
    WIP: 70-642
  4. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    so do you want too build a console application?
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  5. jodsclass

    jodsclass Byte Poster

    170
    3
    39
    Not that hot on C++, been years since I looked at it, but won't you have to compile the code before you can run it?

    I know in Java, you right your code in your text editor, then you compile it, the compiler gives you error codes if there are coding errors, if not it compile snicely.

    I know in Java on a Unix or mac platform you CD to the directory where your .java file is stored, then you run javac filename.java to compile it.

    Then if you want to run it at command prompt its simply java filename

    It may be different for C++ but I'm sure you have to compile the code to track down the errors :)

    Jodsclass
     
    Certifications: BSc IT & Web Development
    WIP: MSc Advanced Computing, Oracle Cert
  6. Alex Wright

    Alex Wright Megabyte Poster

    501
    9
    57
    Yup, but I don't know how! :D
     
    Certifications: 70-680 Configuring Windows 7
    WIP: 70-642
  7. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    You will need to invoke first the compiler then the linker.

    They are both command line apps.

    They will require various environment vars to be set.

    Look into vcvars.bat and the compiler command line and the linker command line.

    http://www-unix.mcs.anl.gov/mpi/mpich1/docs/mpichntman/node10.htm

    People usually use make or an IDE to resolve the dependancies and set up the environment, for a simple program like you describe you should be able to create a bat file and get it working.

    I really would advise against C++ for a first language, maybe C but not C++. It took me years to fully learn C++ and i knew various languages and assembler.

    There are many free C++ compilers including microsofts and gnus, Microsoft express IDE is also free.
     
  8. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    I'm affraid I have to disagree. If C++ is your first language, there will be no problem. If you allready know a language as assembler or Fortran or so, the switch of thinking procedural to object-based is very big. If you start with object based thinking, you will not be hampered with the old way of everything sequencial and in order.
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  9. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    I have no problem with different programming paradigms, one of thoose othe languages was Smalltalk ! I was schooled on OO before I learnt C++.

    The problems are that C++ is a deeply technical language, does that mean that you can't write simple programs ? Of course not, but there is a very long bit of rope and a good chance some people may use it...
     
  10. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    Also C is much more complex then languages as Pascal or Algol or Cobol or what have you.
    Me myself had big problems in getting the OO concepts in my head.
    Just my opinion, no point for discussion.
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  11. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    The basic OO concept of encapsulation was already practiced in many non OO languages like COBOL and C it was just not enforced or directly supported. Other OO concepts could be implemented although would be a bit unwieldy, C++ initially was called C with classes after all and alot of it was implemented in C along with a special preprocessor.

    I would put C, Algol and Pascal on the same level roughly in terms of learning difficulty, Algol had some very nasty issues related to parsing and whitespace layout. COBOL could be fairly complex in the way it operated on data, has 1000's of keywords and also has column based layout, I would argue it can be considered harder than C but again thats just my opinion.

    There is a C++0x initiative thats rather reminiscent of Java/C# illustrating that many agree the language is too complex and does not adequately support some of the higher level primitives required by todays developer. Avoiding the pitfalls of C++ takes great skill, learning to do this takes years, years which might be better spent for a newcomer, many think they understand the language when they are just scratching the surface.

    Don't get me wrong, its a great language, I wound't have developed in it for 9 years otherwise, but it is complicated.
     
  12. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    I'd have to agree with jodsclass. It's hard enough to learn how to program without having to think about garbage collection and all the other stuff that C++ requires a programmer to take into consideration.

    I'd much rather learn a language that will do all those things for me first, and then step up to languages that require so much more from the programmer.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  13. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    The only way to check if a program will compile is to compile it.

    If you won't get the Microsoft compiler for some then I would recomend downloading and installing the Bloodshed compiler. It includes a complete IDE (Integrated Development Environment).

    The only downside is that it won't be the same as the M$ one, so you will have to relearn the M$ IDE.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  14. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    There's also this :-

    http://www.eclipse.org/callisto/c-dev.php

    this

    http://gcc.gnu.org/


    this

    http://www.intel.com/cd/software/products/asmo-na/eng/219771.htm

    this

    http://msdn2.microsoft.com/en-gb/express/aa700735.aspx

    and this

    http://www.thefreecountry.com/compilers/cpp.shtml

    Thats the beauty of open standards, everyone can join in.

    If you want to do much windows specific programming you will also need the platform SDK :-

    http://www.microsoft.com/downloads/...43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en

    The exact version will depend on your OS.
     
  15. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    Navigate to the folder where your .cpp files are in the command shell. At the prompt type:

    type <filename>.cpp

    where <filename> is the name of the .cpp files. Wildcards like '?' and '*' are also allowed, of course.

    About the compiler, since you know that you will be using VS2005 you might as well give yourself a head start by downloading Microsoft Visual C++ 2005 as the integrated development environment, otherwise know as the 'IDE', is practically identical to the professional product, and the same steps are required to build your code.

    About the differences between C and C++: They are both different languages! Yes, you can write C code in a C++ invironment, but the methods used to compile the code in a C++ environment are marginally different in that if you wish to compile 'pure C code' you often have to specify to the C++ compiler that you wish to compile the code as pure C. Also the traditional C headers are wrapped in C++ classes to maintain C++ compatiblity - the details go on. Finally, obviously, you cannot in any way compile a C++ program in a C environment and this is the most obvious point that makes them different.

    How similar is C/C++ to other programming languages? I most definately would not group C with Algol and Pascal. Last time I looked Algol and Pascal had no low-level functionality and C has a much more free form when coding. C makes use of header files and the way that data is shared between variable declarations within source files is unique, etc.

    C++ as a first language? If you're being mentored by a professional C++ programmer then there's no reason why it shouldn't be your first language if you are a confident coder. If you were learning on your own, or the mentor is his/herself weak with the language then it is a bad idea as a first language generally.

    Sorry if I've reiterated some of what people have already said, but I'm really tired at the mo'. :dry
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  16. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Like I said its customary for people to either learn another language, C or 'C++ as a better C' first. With C a certain amount of 'unlearning' may be necessary as there are some differences. 'C++ as a better C' generally involves teaching the subset of C++ that is close to C avoiding many C++ features and issues, as well as issues involved in old C syntax versus C++.

    Ok, well if you do insist on learning C++ *1ST*, heres my study List :biggrin

    Essential C++

    The C++ Programming Language

    The Standard Template Library

    Effective C++

    More Efffective C++

    That will give you a good understanding of the core language.

    You will then need to learn various other stuff. Consider these for slightly more advanced computer science/C++ :-

    Ruminations on C++: A Decade of Programming Insight and Experience

    Design Patterns

    Effective STL

    Algorithms

    And yes I have read all the above and more...

    I've not read these but they are supposed to be good, be interesting to hear if anyone here has, and what they think...

    Modern C++ Design: Generic Programming and Design Patterns Applied

    C++ Common Knowledge: Essential Intermediate Programming

    I would also reccomend you take a good look at boost once you have grasped the STL, theres also various books on it and parts of it are in the process of being incorporated into the C++ standard as TR1/TR2.

    Notice we still haven't really covered alot of stuff, various 3rd party libraries, networking/RPC/web services/distributed apps, IO, databases, GUI/graphics, design/OO, concurrency/threading, architecture, software engineering, planning, project management, testing, debugging, data formats, integration, operating system services, application servers, enterprise apps/middleware, etc.

    This is why I reccomend another language first unless you really need to learn C++ for your career goal ASAP, because with C++ you will spend a loooong time learning the language before you can deal with wider concepts.

    I also can't reccomend the ACCU highly enough they run some very good conferences with internationally renowned speakers.
     
  17. Alex Wright

    Alex Wright Megabyte Poster

    501
    9
    57
    Thanks guys, some excellent responses there - much appreciated! :)
     
    Certifications: 70-680 Configuring Windows 7
    WIP: 70-642
  18. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
  19. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    Isn't this sort of a non-sequitur? How can one be a "confident coder" if you don't know how to write code yet? This would seem to be a catch-22 in which C++ is alright for a first language if you already know how to program and are already confident in your own abilities to code. The two would seem to me to be mutually exclusive. Did I somehow miss something here?
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  20. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    The problem here is that C++ is nowadays immensly complicated! So while I agree that the statement reads a little oddly, I support the idea that you shouldn't really tackle it as a first language without very good guidance.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.