Thread: Array

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    Array

    How is a string vector array declared using a Form application ?

    This seems to work for int in a Form Application:
    Code:
    std::vector<int> Value(10);
    But if you change int to string in the same example the compiler says that
    'std::vector' : class has no constructors

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    What is the exact error message?

    Code:
    std::vector<std::string> Value(10);
    should be correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    yes that worked great...thanks. The compiler said that string also not was declared so std:: was the trick.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I have an array like this:

    System::IO:: Directory::GetFiles(Files,"*.txt");

    Files is in a format: cli::array<Type,dimension> ^

    Is there a method to convert in this case Files to a System::String ^
    Last edited by Coding; 02-12-2008 at 08:16 PM.

  5. #5
    coder
    Join Date
    Feb 2008
    Posts
    127
    Quote Originally Posted by coding
    std:: was the trick.
    You may avoid typing std:: everytime simply with "using namespace" put just after your include's
    Code:
    #include <iostream>
    using namespace std;
    
    vector<string> Value(10);

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    The use of using directives outside local code kinda defeats the whole purpose of namespaces and it may originate unnecessary name clashes.

    If anything, I'd advise for it inside function definitions where you have more control over the names. But as for the ::std namespace, really probably the best option is to get used to simply type std::

    After a while, you'll get used to it and will even benefit from easier to debug code.
    Last edited by Mario F.; 02-12-2008 at 08:25 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    that worked great.. I will keep both tips in mind.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    NO! Stop using native code inside your managed environment. I don't know how many times I need to tell you.
    std::vector was not designed to handle managed types and managed was not designed to handle native types without interop, and then it goes back to managed again.
    Stop using native!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I am very confused about what is managed and unmanaged.
    More or less for the moment I just know that there is something called managed and unmanged and that native is another word for unmanaged I think.
    I dont know what it is Really ! Just the fact that there is a difference.

    So when doing Windows Application Form in C++. This meens that I will only do Managed Code ?
    My CLR Console Application with 15 pages of code that I have done. Is this unmanaged code ?

    I will go to the library borrow some books and read about it to see if I understand better.

    Like std::vector<std::string> Value(10); is Native then. This I use in the CLR application.
    I also use, a simple example: int Value2 = 10; Is this managed or unmanged. I have no Id&#233;a.

    Does it meen that I have to know Every syntax in order to know If that syntax is managed or unmanaged code. In my head it look like this for the moment.
    So I dont use Native code with purpose. This is because I dont understand the differences really. Just the fact that it is a difference.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then stop using C++. C++ is native and C++/CLI, Microsoft's own C++ standard, is managed.
    To avoid this, use C#. Then you can't use (or more likely won't) use native C++.
    I'm going to tell you this, though: everything in the std namespace and headers are native. Everything managed are grouped into namespaces such as System and cli.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Coding View Post
    I am very confused about what is managed and unmanaged.
    More or less for the moment I just know that there is something called managed and unmanged and that native is another word for unmanaged I think.
    I dont know what it is Really ! Just the fact that there is a difference.
    I know. It's not your fault, Coding. It really isn't.

    We say unmanaged when we refer to C++.

    Managed is C#, C++/CLI, VB.Net. Microsoft creations.

    So when doing Windows Application Form. This meens that I will only do Managed Code ?
    Yup. You won't be programming in C++. The syntax is similar because Microsoft intended that way as a means to invite C++ programmers into .Net being that the syntax would be similar (the same happened between VB and VB.Net)

    My CLR Console Application with 15 pages of code that I have done. Is this unmanaged code ?
    Nope. It's managed. CLR is part of the .Net framework.

    Code:
     I will go to the library borrow some books and read about it to see if I understand better.
    No need. It's easier if you simply download and install Visual Studio C++ Express, instead of Visual Studio C# Express which it seems is what you are using.

    Does it meen that I have to know Every syntax in order to know If that syntax is managed or unmanaged code.
    Nope. You just need to know which compiler you are using. Use Visual Studio C++ Express.

    So I dont use Native code with purpose. This is because I dont understand the differences really. Just the fact that it is a difference.
    I say if you are getting used to it, you should keep using it. It's as good as any other language for learning purposes and who knows, you may even end up liking it. I'd take 1 happy managed code programmer for every 20 unhappy C++ programmers.

    What you need though is move to the C# forum. You will get less confused there because people will reply to you with managed code in mind.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I have to read a little about this to have a better understanding.
    However it could be a possibility to change to C# perheps.
    Though anyway I will have to "convert" my now existing CLR Console code to function within a buttonControl with meens int:s, vectors, Readfiles, Write to files etc...

    So to make life easier I can do this to C# as it is kind of similar. Am I thinking right here ?

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It depends.
    You seem to bordering between native and managed here.
    So you should typically choose one. If managed, go with C#. If native, go with C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM