Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with Adding a vector to my program

Problem with Adding a vector to my program

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiographics
21 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jeff Patterson
    wrote on last edited by
    #1

    I have this silly program I am doing for class. I want to add a vector to it but I get the below error. I have added to my working program #include using namespace std; vector v; and then get this error. With out the 3 lines my program works fine. I'm not even using the vector anyplace yet. --------------------Configuration: CIS279_8 - Win32 Debug-------------------- Compiling resources... D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE/eh.h(32) : error RC2188: #error : "eh.h is only for C++!" RC : fatal error RC1116 : RC terminating after preprocessor errors Error executing rc.exe. Creating browse info file... CIS279_8.exe - 2 error(s), 0 warning(s) Any Ideas? Thanks, Jeff Patterson Programmers speak in Code. www.anti-dmca.org

    C D C 3 Replies Last reply
    0
    • J Jeff Patterson

      I have this silly program I am doing for class. I want to add a vector to it but I get the below error. I have added to my working program #include using namespace std; vector v; and then get this error. With out the 3 lines my program works fine. I'm not even using the vector anyplace yet. --------------------Configuration: CIS279_8 - Win32 Debug-------------------- Compiling resources... D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE/eh.h(32) : error RC2188: #error : "eh.h is only for C++!" RC : fatal error RC1116 : RC terminating after preprocessor errors Error executing rc.exe. Creating browse info file... CIS279_8.exe - 2 error(s), 0 warning(s) Any Ideas? Thanks, Jeff Patterson Programmers speak in Code. www.anti-dmca.org

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      what is the name of the file to which you added the #include ? is it foo.c or foo.cpp ? -c


      There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

      Smaller Animals Software

      J 2 Replies Last reply
      0
      • C Chris Losinger

        what is the name of the file to which you added the #include ? is it foo.c or foo.cpp ? -c


        There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

        Smaller Animals Software

        J Offline
        J Offline
        Jeff Patterson
        wrote on last edited by
        #3

        oops guess that is important. #include Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

        1 Reply Last reply
        0
        • C Chris Losinger

          what is the name of the file to which you added the #include ? is it foo.c or foo.cpp ? -c


          There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

          Smaller Animals Software

          J Offline
          J Offline
          Jeff Patterson
          wrote on last edited by
          #4

          something strange is going on here. #include Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

          C 1 Reply Last reply
          0
          • J Jeff Patterson

            something strange is going on here. #include Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #5

            you need to put source code inside <pre> tags (and put spaces around any angle brackets. otherwise, the CP boards eat them... -c


            There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

            Smaller Animals Software

            1 Reply Last reply
            0
            • J Jeff Patterson

              I have this silly program I am doing for class. I want to add a vector to it but I get the below error. I have added to my working program #include using namespace std; vector v; and then get this error. With out the 3 lines my program works fine. I'm not even using the vector anyplace yet. --------------------Configuration: CIS279_8 - Win32 Debug-------------------- Compiling resources... D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE/eh.h(32) : error RC2188: #error : "eh.h is only for C++!" RC : fatal error RC1116 : RC terminating after preprocessor errors Error executing rc.exe. Creating browse info file... CIS279_8.exe - 2 error(s), 0 warning(s) Any Ideas? Thanks, Jeff Patterson Programmers speak in Code. www.anti-dmca.org

              D Offline
              D Offline
              Daniel Turini
              wrote on last edited by
              #6

              What is the extension of your source file? This error is similar to when you name a file .C and the C++ mode will be turned off. Be sure to name it C++ and check your project settings to be sure that C++ compilation is enabled. My latest article: SQL Server DO's and DONT's[^]

              J 1 Reply Last reply
              0
              • D Daniel Turini

                What is the extension of your source file? This error is similar to when you name a file .C and the C++ mode will be turned off. Be sure to name it C++ and check your project settings to be sure that C++ compilation is enabled. My latest article: SQL Server DO's and DONT's[^]

                J Offline
                J Offline
                Jeff Patterson
                wrote on last edited by
                #7

                I was trying to include it in my created .h file. Why must I include this in a cpp file and declare it in a .h file? It is working now but this seems nonstandard. Am I missing something? Thanks Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                D 1 Reply Last reply
                0
                • J Jeff Patterson

                  I was trying to include it in my created .h file. Why must I include this in a cpp file and declare it in a .h file? It is working now but this seems nonstandard. Am I missing something? Thanks Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                  D Offline
                  D Offline
                  Daniel Turini
                  wrote on last edited by
                  #8

                  Jeff Patterson wrote: It is working now but this seems nonstandard. Yes, it is nonstandard, but it's a very common feature of compilers. For easier use of old C code, they only enable C++ extensions in files with specific extensions, like cpp, cc, cxx, and so on. You can always force C++ compilation, even without these extensions. My latest article: SQL Server DO's and DONT's[^]

                  J 1 Reply Last reply
                  0
                  • D Daniel Turini

                    Jeff Patterson wrote: It is working now but this seems nonstandard. Yes, it is nonstandard, but it's a very common feature of compilers. For easier use of old C code, they only enable C++ extensions in files with specific extensions, like cpp, cc, cxx, and so on. You can always force C++ compilation, even without these extensions. My latest article: SQL Server DO's and DONT's[^]

                    J Offline
                    J Offline
                    Jeff Patterson
                    wrote on last edited by
                    #9

                    Thanks. Since you have grabbed my curiosity now :) How do you force C++ compilation? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                    D 1 Reply Last reply
                    0
                    • J Jeff Patterson

                      Thanks. Since you have grabbed my curiosity now :) How do you force C++ compilation? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                      D Offline
                      D Offline
                      Daniel Turini
                      wrote on last edited by
                      #10

                      You can use one of the Tc, /Tp, /TC, /TP to specify source file type or, in VC.NET (I don't recall where it is in VC 6.0), open the project's Property Pages, "C/C++", "Advanced", "Compile As" My latest article: SQL Server DO's and DONT's[^]

                      J 1 Reply Last reply
                      0
                      • D Daniel Turini

                        You can use one of the Tc, /Tp, /TC, /TP to specify source file type or, in VC.NET (I don't recall where it is in VC 6.0), open the project's Property Pages, "C/C++", "Advanced", "Compile As" My latest article: SQL Server DO's and DONT's[^]

                        J Offline
                        J Offline
                        Jeff Patterson
                        wrote on last edited by
                        #11

                        Thanks and I'll have a look. Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                        1 Reply Last reply
                        0
                        • J Jeff Patterson

                          I have this silly program I am doing for class. I want to add a vector to it but I get the below error. I have added to my working program #include using namespace std; vector v; and then get this error. With out the 3 lines my program works fine. I'm not even using the vector anyplace yet. --------------------Configuration: CIS279_8 - Win32 Debug-------------------- Compiling resources... D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE/eh.h(32) : error RC2188: #error : "eh.h is only for C++!" RC : fatal error RC1116 : RC terminating after preprocessor errors Error executing rc.exe. Creating browse info file... CIS279_8.exe - 2 error(s), 0 warning(s) Any Ideas? Thanks, Jeff Patterson Programmers speak in Code. www.anti-dmca.org

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #12

                          Jeff Patterson wrote: using namespace std; There really is no point in having namespaces if you're going to pull them into the global namespace holus bolus. You should instead have using statements like this using std::vector; Yes, all the books do it wrong, I don't know why. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                          C 1 Reply Last reply
                          0
                          • C Christian Graus

                            Jeff Patterson wrote: using namespace std; There really is no point in having namespaces if you're going to pull them into the global namespace holus bolus. You should instead have using statements like this using std::vector; Yes, all the books do it wrong, I don't know why. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                            C Offline
                            C Offline
                            Chris Losinger
                            wrote on last edited by
                            #13

                            Christian Graus wrote: all the books do it wrong, I don't know why. because it's not wrong. if "using namespace x" was wrong, his holiness Bjarne wouldn't have included it. -c


                            There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                            Smaller Animals Software

                            C 1 Reply Last reply
                            0
                            • C Chris Losinger

                              Christian Graus wrote: all the books do it wrong, I don't know why. because it's not wrong. if "using namespace x" was wrong, his holiness Bjarne wouldn't have included it. -c


                              There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                              Smaller Animals Software

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #14

                              Chris Losinger wrote: if "using namespace x" was wrong, his holiness Bjarne wouldn't have included it. I'm afraid it's 'his holiness' that you're arguing with. using an entire namespace is included for a number of reasons, but we are strongly discouraged from using it, unless it is within a very limited scope, such as including all of one namespace within another. Do you own 'The C++ Programming Language' ? My copy is not here, but if you look up the chapter on namespaces, it's all in there. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                              C 1 Reply Last reply
                              0
                              • C Christian Graus

                                Chris Losinger wrote: if "using namespace x" was wrong, his holiness Bjarne wouldn't have included it. I'm afraid it's 'his holiness' that you're arguing with. using an entire namespace is included for a number of reasons, but we are strongly discouraged from using it, unless it is within a very limited scope, such as including all of one namespace within another. Do you own 'The C++ Programming Language' ? My copy is not here, but if you look up the chapter on namespaces, it's all in there. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                C Offline
                                C Offline
                                Chris Losinger
                                wrote on last edited by
                                #15

                                Christian Graus wrote: but we are strongly discouraged from using it don't care. it's part of the language. if it's so bad, he should've decreed a compiler warning. yes, i understand your point about "using namespace std" defeats the purpose. but, i disagree that people need to be hammered with dogma when they're trying to learn the basics. -c


                                There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                Smaller Animals Software

                                C A 2 Replies Last reply
                                0
                                • C Chris Losinger

                                  Christian Graus wrote: but we are strongly discouraged from using it don't care. it's part of the language. if it's so bad, he should've decreed a compiler warning. yes, i understand your point about "using namespace std" defeats the purpose. but, i disagree that people need to be hammered with dogma when they're trying to learn the basics. -c


                                  There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                  Smaller Animals Software

                                  C Offline
                                  C Offline
                                  Christian Graus
                                  wrote on last edited by
                                  #16

                                  Chris Losinger wrote: if it's so bad, he should've decreed a compiler warning. See, this comes down to C++ not being a language for idiots. Once you get flooded with warnings, will you really read them all, or none of them ? Chris Losinger wrote: i disagree that people need to be hammered with dogma when they're trying to learn the basics. I disgaree totally. People are creatures of habit, and half the reason so much bad code is written is because people form bad habits early on. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                  C R 2 Replies Last reply
                                  0
                                  • C Christian Graus

                                    Chris Losinger wrote: if it's so bad, he should've decreed a compiler warning. See, this comes down to C++ not being a language for idiots. Once you get flooded with warnings, will you really read them all, or none of them ? Chris Losinger wrote: i disagree that people need to be hammered with dogma when they're trying to learn the basics. I disgaree totally. People are creatures of habit, and half the reason so much bad code is written is because people form bad habits early on. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                    C Offline
                                    C Offline
                                    Chris Losinger
                                    wrote on last edited by
                                    #17

                                    Christian Graus wrote: I disgaree totally i'm shocked. :) -c


                                    There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                    Smaller Animals Software

                                    1 Reply Last reply
                                    0
                                    • C Christian Graus

                                      Chris Losinger wrote: if it's so bad, he should've decreed a compiler warning. See, this comes down to C++ not being a language for idiots. Once you get flooded with warnings, will you really read them all, or none of them ? Chris Losinger wrote: i disagree that people need to be hammered with dogma when they're trying to learn the basics. I disgaree totally. People are creatures of habit, and half the reason so much bad code is written is because people form bad habits early on. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                      R Offline
                                      R Offline
                                      Rickard Andersson20
                                      wrote on last edited by
                                      #18

                                      Christian Graus wrote: Once you get flooded with warnings, will you really read them all, or none of them ? I've learned from many books that you're going to treat warnings like errors. But sometimes you just have to ignore some warnings, like:

                                      while(1)
                                      {
                                      // do something
                                      }

                                      This will cause a warning (warning level 4 only I think) that says it's a constant expression, even if you do a break inside the brackets! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

                                      C 1 Reply Last reply
                                      0
                                      • R Rickard Andersson20

                                        Christian Graus wrote: Once you get flooded with warnings, will you really read them all, or none of them ? I've learned from many books that you're going to treat warnings like errors. But sometimes you just have to ignore some warnings, like:

                                        while(1)
                                        {
                                        // do something
                                        }

                                        This will cause a warning (warning level 4 only I think) that says it's a constant expression, even if you do a break inside the brackets! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

                                        C Offline
                                        C Offline
                                        Christian Graus
                                        wrote on last edited by
                                        #19

                                        Rickard Andersson wrote: while(1){ // do something} I'd regard this as a bad idea. Why not while (whatever condition you end up breaking on), or a do...while if you want to make sure it runs once ? But you're right, it's generally good to treat warnings as errors, which is why using namespace... should not be a warning, there are places where it is useful. The whole basis of C++ is to provide the constructs that you may one day need, and not to confine you to what the impliments think is a good idea. That's one reason it is so powerful. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                        R 1 Reply Last reply
                                        0
                                        • C Chris Losinger

                                          Christian Graus wrote: but we are strongly discouraged from using it don't care. it's part of the language. if it's so bad, he should've decreed a compiler warning. yes, i understand your point about "using namespace std" defeats the purpose. but, i disagree that people need to be hammered with dogma when they're trying to learn the basics. -c


                                          There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                          Smaller Animals Software

                                          A Offline
                                          A Offline
                                          Alvaro Mendez
                                          wrote on last edited by
                                          #20

                                          I agree with you. I've actually gone as far as to do the "unthinkable!": put using namespace std; inside the precompiled header. :eek: Oh the horror! The result? Clean, Easy-to-read code! Unfortunately, like you say, a lot of people prefer to preach, "Don't you ever do this", instead of "Doing this is OK as long as you're aware of such and such potential problems". When it comes to the using directive, the only problem that can occur is name clashes, which the compiler is happy to tell you about, and can be corrected with the scope-resolution operator. Regards, Alvaro


                                          Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups