• Advertisement

Archived

This topic is now archived and is closed to further replies.

are there c++ updates?

This topic is 5104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just started c++ but have been doing Java for a while now. I was wondering if there are updated versions of c++ that have to be downloaded, like with Java. I am using Visual C++ 6. I am asking bcasue when I needed help creating a sting I found 2 solutions. One is to use a char string[10], while the other was to #include <string> and then just declare a string. Obviously I got the first way to work, but not the second.

Share this post


Link to post
Share on other sites
Advertisement
The newest C++ standard is 5 years old. But your compiler isn't even compliant to that. You should upgrade to Visual Studio .NET 2003 (version 7.1)

char string[10] is in fact not a string, but an array of bytes.

std::string from is an object, that resembles the function of a native string in other languages.

You can't compare them directly.

This should work:

#include <string>
#include <iostream>

int main()
{
std::string string("Hello, World!");
std::cout << string << std::endl;
}


[edited by - noVum on March 5, 2004 5:24:11 PM]

Share this post


Link to post
Share on other sites
There are several answers to this question:

One, compilers often have service packs and new versions. MSVC 6 has been patched up to service pack 5, IIRC. I would heartily recommend downloading any necessary service packs for MSVC 6. Of course, it''s been completely superceded by MSVC 7 and 7.1.

Another answer is that the C++ standard itself has changed over the years. The current version of the standard was released in 2003. However, there is no way to download a patch to MSVC 6 to get it to conform to the current standard. As far as I know, not even the current versions of Visual C++ still under development will conform to the current standard.

Also, unlike Java, because C++ is compiled into native code, you don''t need to download new runtime environments or anything like that.

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
The newest C++ standard is 5 years old.


Wrong. It''s less than a year old, it was published in 2003 as ISO/IEC 14882:2003.

Share this post


Link to post
Share on other sites
quote:
Wrong. It's less than a year old, it was published in 2003 as ISO/IEC 14882:2003.

Apparently you are right. Is this C++0x ?


[edited by - noVum on March 5, 2004 5:29:01 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
No. The latest release is ISO C++ 98 and the next version has the "codename" C++0x, but is not ready yet.


Incorrect. TC1 got released last year.

quote:
Minutes of ISO WG21 Meeting, April 6, 2003
A revised edition of the IS with TC1 changes but without change bars will be published. This will be document 14882:2003(E).

Share this post


Link to post
Share on other sites
quote:
Original post by wolfbane
I just started c++ but have been doing Java for a while now. I was wondering if there are updated versions of c++ that have to be downloaded, like with Java. I am using Visual C++ 6.


C++ is a programming language, it's not a program. Visual C++ 6 is a program you can use to write and compile programs written in C++ and there are newer versions of it available but they're not free. To get a free C++ development environment you could try e.g. Dev-C++ whose compiler (MingW) also follows the C++ standard much better than VC.
quote:

One is to use a char string[10], while the other was to #include <string> and then just declare a string. Obviously I got the first way to work, but not the second.


You won't need any updates to get the methods you described working. The second way is preferable and easier to work with. Remember to put the following line after the #include lines:
using namespace std;  

Otherwise you would have to write 'std::' in front of the std variable declarations (e.g. std::string mystr)

EDIT: Damn you guys are fast!


[edited by - nonpop on March 5, 2004 5:32:03 PM]

Share this post


Link to post
Share on other sites
You shouldn't use "using namespace std;"
This defeats the entire purpose of namespaces. Especially don't do that in headers.

quote:
Dev-C++ whose compiler (MingW) also follows the C++ standard much better than VC.

Very wrong. VS .NET 2003 has one of the most standard compliant compilers that exist.

[edited by - noVum on March 5, 2004 5:33:42 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
You shouldn''t use "using namespace std;"
This defeats the entire purpose of namespaces. Especially don''t do that in headers.

quote:
Dev-C++ whose compiler (MingW) also follows the C++ standard much better than VC.

Very wrong. VS .NET 2003 has one of the most standard compliant compilers that exist.


I was comparing it against VC6 (but apparently not so clearly)

Share this post


Link to post
Share on other sites
Just curious, does anyone know what ISO/IEC 14882:2003 contains, I couldn''t find any info on it''s contents, other than paying the ISO for a copy.

Share this post


Link to post
Share on other sites
quote:
Original post by cozman
Just curious, does anyone know what ISO/IEC 14882:2003 contains, I couldn''t find any info on it''s contents, other than paying the ISO for a copy.


792 pages of technical minutia and language lawyer babble. I have a hard copy sitting next to my keyboard. The British Standards Institute through Wiley publishers, has put it out in book form for about $65 US.

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
Apparently you are right. Is this C++0x ?


It''s TC1. I think the C++0x moniker has been hijacked to refer to the next major revision to the language standard. (Not 100% sure about this. I don''t keep as close track to the standards committee as I did even a year ago.)

Share this post


Link to post
Share on other sites
And what are the important changes in the new standard?

Share this post


Link to post
Share on other sites
using namespace std;

does NOT defeat the WHOLE purpose of the namespace existing in the first place ... and here's why:

1. The namespace exists in the first place so that only code which CHOOSES to add "using" directives will be affected by it ... hence the above code chooses to do so, and therefore gets exactly what it requested. This file can still sit in the same project as another file which does NOT do add a top-level namespace using statement, and therefore the purpose of the namespace is preserved.

2. The namespace's existence is known by the compiler EVEN IF a using namespace std; is uses, so in this case:

using namespace std;
using namespace myLib;
using namespace someoneElsesLib;

if all 3 namespaces include a "list" class, then you MUST qualify the list class when you use it, but ONLY the list class ... so you could do:

string firstName, lastName;
myLib::list students;

and there is no trouble, even though you did a using which in theory brings both lists into the current namespace.

This would NOT have been possible without namespaces.

3. The standard library would NEVER have been put in a namespace is there was no "using namespace std;" equivelent ... because a goal was that all existing code be easy to convert to the new langauge, and they do NOT intent for users to write bigger more bloated code, but less, more clear code ...

so this:


#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <iostream>

std::map<std::string, std::vector<std::fstream> > fileGroups;
std::cout << "beginning program" << std::endl;

//or this:



#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <iostream>

using std::string;
using std::fstream;
using std::vector;
using std::map;
using std::cout;
using std::endl;
// and plan to add "pair", "cin", and other items as you use them, and don't forget to remove them if you don't need them anymore.


map<string, vector<fstream> > fileGroups;
cout << "beginning program" << endl;


are not superior to this:


#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <iostream>

map<string, vector<fstream> > fileGroups;
cout << "beginning program" << endl;


[edited by - Xai on March 5, 2004 6:43:19 PM]

[edited by - Xai on March 5, 2004 6:44:15 PM]

Share this post


Link to post
Share on other sites
however your first example is clearer on the location you are drawing them from, std::map shows you in one line that you are using the map container from the std namespace, where as a using namespace std; exists only in one point, and if you dont happen to read that line it isnt clear where the map is coming from (NEVER assume).
So, while for small things the using keyword is handy, for anything remotely large it just doesnt make sense to use it, by doing so you lose ''in place'' explicate infomation which hinders the self documenting process and if anything makes the code less clear as to its intent.

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
And what are the important changes in the new standard?

Mostly it''s just fiddly corner case clarifications (like clarifying that sizeof on a enum type inside the enum types declaration is undefined or specifying that accessing storage of an object may be done through lvalues of compatible types rather than lvalues of the stored type.) There''s one or two of what seem to be punctuation/grammar corrections. Some additional examples to help clarify things. I don''t think there''s anything really major in it, unless you''re a compiler writer, in which case some of the changes will make your job much happier. After all, ISO/IEC 14882:2003 is just a technical corrigenda, not a major revision like C99 was for the C language.

Share this post


Link to post
Share on other sites
hey guys,

i own visual studio 6 and also visual studio .net 2003. (school packages). anyway, ive been using vc++ 6 instead of .net because i find vc++ to be a nice IDE. i think its less cluttered, and easier to work with. but am i missing anything by not using the .net? do you think i should jsut start using it and get used to it? thanks for any help

Share this post


Link to post
Share on other sites
here''s the list of things I noticed when i went from VC++6, to VS .NET 2003 ...

1. The C++ Compiler pretty much works right now, and standard C++ program I had written which worked at school or on Borland C++ Builder now works in VC 7.1 (I had personally written code which was ''correct'' but did not work correctly under VC 6). This improvement in the compiler also allows you to use the boost library almost completely now (www.boost.org) and also use the techniqes in "Modern C++ Design" if you are so inclined.

2. The error messages for programs using templates are more clear / accurate (or maybe I just understand them now ... not 100% sure).

3. The IDE does not break when you try to open more than 3 copies at once (VC 6 would start acting VERY wrong if I had 4 projects open at once).

4. Intellisense works in more cases now, and much more often correctly drills into included non standard library, non local project code.

5. The project xml files are fairly sensible, and you can easily manipulate them by hand, to see why different projects are different, and to cut and paste elements from one to another (you also learn a lot seeing exactly which settings the default "debug" and "release" targets do differently). The solution files are also fairly sensible, although not xml, still very hand readable / editable. This was VERY important to me, because at one point I was maintaining a crossplatform build system which had 5 versions: VC6, GCC on BeOS, GCC on FreeBSD/Linux, Borland C++ Builder, and VS .NET - the GCC/make system was the easiest to setup and maintain, but the VS .NET system is second.

6. Repeat #1

7. Repeat #1 (this really is a BIG deal for the code I write).

The only bad thing about VS .NET is that it is slower than VC 6 to compile and also generated slower code in many cases. If I remember correctly, some of this was worst in VS .NET and fixed in VS .NET 2003 ... BUT some of it is caused by the fact that VC now supports a better C++ model AND has better debugging and error detection features ... and therefore will not every likely be as nimble as VC 6 (but it isn''t enough different that I can tell).

I use C# now at work, not C++ ... so I can''t say much about the real day to day, but I can say, with C#, I get annoyed by the compiler and IDE every week, EVERY WEEK!!! ... but in the VC 6 days this was closer to every other day ... I am VERY happy with 2003 compared to 6 (although I too hate the candy interface on my laptop at work 1024x768 isn''t enough for ANY visual studio IDE ... but at 1280x1024 at home, I like 2003 just fine). I recommend you take some time playing with "pinning" and "unpinning" the panels in various arangements, and also realize you can completely change the way they dock to the IDE and each other.

good luck

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
And what are the important changes in the new standard?
Most importantly, are std::vectors contiguous now?

Share this post


Link to post
Share on other sites
quote:
Original post by Beer Hunter
Most importantly, are std::vectors contiguous now?

Sure.

Has there ever been an implementation which was non-contiguous?

Share this post


Link to post
Share on other sites
quote:
Has there ever been an implementation which was non-contiguous?

No.

[edited by - noVum on March 6, 2004 9:21:06 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Trap
quote:
Original post by Beer Hunter
Most importantly, are std::vectors contiguous now?

Sure.

Has there ever been an implementation which was non-contiguous?


Yes, there has been. I wrote one myself to demonstrate that it could be done and still be compliant with respect to the original standard.

Anyways, TC1 adds this sentence to the end of paragraph 1 in 23.2.4: "The elements of a vector are stored contiguously, meaning that if v is a vector<T, Allocator> where T is some type other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()."

Share this post


Link to post
Share on other sites
I know that one can write such a vector. There even is a paper which suggest a non-contiguous vector-type: "Resizable Arrays in Optimal Time and Space".

But i believe no c++-compiler was ever distributed with such a non-contiguous vector.

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
792 pages of technical minutia and language lawyer babble. I have a hard copy sitting next to my keyboard. The British Standards Institute through Wiley publishers, has put it out in book form for about $65 US.


The Wiley hardcover includes TC1? Hmmm... time to place an order.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites

  • Advertisement