Copy and pasting thingy..

Nanor

Well-Known Member
I'm starting to learn C++ as I'm undoubtedly going to need it later on in my career, and I'm using a guide that elDiablo kindly posted me Teach Yourself C++ in 21 Days. Now, that's great and I'm coming on nicely, but if you look at an example of any of the code, you'll see it looks like this:

Code:
1:   #include <iostream.h>
2:
3:   int main()
4:   {
5:     cout << "The size of an int is:\t\t"    << sizeof(int)    << " bytes.\n";
6:     cout << "The size of a short int is:\t" << sizeof(short)  << " bytes.\n";
7:     cout << "The size of a long int is:\t"  << sizeof(long)   << " bytes.\n";
8:     cout << "The size of a char is:\t\t"    << sizeof(char)   << " bytes.\n";
9:     cout << "The size of a float is:\t\t"   << sizeof(float)  << " bytes.\n";
10:    cout << "The size of a double is:\t"    << sizeof(double) << " bytes.\n";
11:
12:        return 0;
13: }

Don't worry about what the code does, it just tells the size of integers and characters et cetera, but what annoys me is the numbers down the left hand side of the code, when I copy and paste that code above into my compiler, it doesn't recognise those numbers as something to tell me what line it is.

Instead of editing all the numbers out, or putting /* */'s around them I'd like to be able to copy and paste without selecting those. If you open command prompt, right click and select mark, that allows you to highlight text there, but not the same way as browsers and I was wondering if there was a way to do that in browsers? I'd be most appreciative if you could tell me how. :)
 

Ronin Storm

Administrator
Staff member
What are you using to write that code?

Line numbering is something that good text editors do well (Textpad for example) and if they also do syntax highlighting for C++ (Textpad does if you download the syntax definition file for C++) then you won't need those line numbers "inline", so to speak... they'll be apparent there for you.

Why C++?
 

Nanor

Well-Known Member
I'm using Dev-C++.

So if I copy my text into textpad, it will do syntax highlighting? What does that mean?

Why am I learning C++? Why not? Plenty of programs are written in C++, and if I have problems I can whine at elD or my brother. :)
 

Ronin Storm

Administrator
Staff member
Syntax highlighting is a bit like the way vBulletin handles PHP codes.

So, if I just write:

Code:
<?php print "Hello world!"; ?>

That's unhighlighted... but in colour...

PHP:
<?php print "Hello world!"; ?>

That's what Textpad does. It isn't, however, a C++ compiler and that you must have in order to turn your work into things that do stuff.

As you say, loads of things are written in C++. Just wondering if you had a specific project in mind that needed C++. Don't want to throw you off track but, personally, I'd point you to .NET languages (C# being the main one I use) as being big news at the moment... or Java, of course. That said, I understand that C++ is the language of choice for computer games developers, at the moment...
 

Iron_fist

Super Moderator
Staff member
i tend use an editor called Notepad++ which has a large library of languages and highlighting built in. A good place to look is Sourceforge as there are lots of nice little programs hidden in there ( plus in a lot of cases source code which is useful to look at once you have some idea what your doing :p)
 

thatbloke

Junior Administrator
I use a very feature-rich text editor at work called Ultra-edit. It's very good! You can make your own language syntax files and keymappings and lots of other stuff that I don't (but probably should) use to make text-editing easier.

but on to your actual question I'm not sure that what you want is actually possible... Maybe there is some kind of plugin for FF that will allow what you want but I'm really not sure that selecting only parts of multiple lines is possible...
 
E

elDiablo

Guest
Well, I have a small present for you, Mr Nanor!

Source code and compiled code of a lovely little java class that just iterates through all given input filenames, reads their lines, removes any leading line numbers (with colon's) and then prints out to a different file. If there aren't any colons after the line numbers, it will remove anything from the start of each line to the first colon, or nothing (if no colon exists in a line). So it's very specific usage. But still, it does what you want.

You even make a new shortcut on your desktop (or wherever you save the file to) with the command "java LineNum new.txt" (assuming you have java 1.4.2 or higher installed correctly). Clicking this shortcut will always convert "new.txt" to "newOut.txt" without the line numbers. So, open two versions of notepad. Use on to open new.txt, and paste all code from the Teach Yourself C++ in 21 days into it (Ctrl+V), and just save with Ctrl+S. Use the other notepad to open "newOut.txt" whenever you run the shortcut.

Obviously, you can call the text files whatever you want, it's your choice. It's not ideal, but it's a start.

Also, all line breaks are windows format ("\r\n"), instead of Unix ("\n") so it works well in simple notpad :) Change the source code and recompile if you're a *nix user.

Enjoy!

Edit - Oh yeah, it's not great code, but it will do. All whitespace is kept because I didn't add in a .trim() to the code, and I can't be bothered to do it now. Next version might find the first alphabetic (or c++ useful (#, /, etc.)) character in the input file on the first line, and use anything before that character that is a non-alphanumeric character as the delimiter. We shall see!
 

Nanor

Well-Known Member
...elDiablo. I say these 4 words many, many times. Sometimes without heart, and sometimes with, but I mean this from the bottom of my heart. I WANT YOUR BABIES!
 
Top