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. vector(wstring) to System::String ?

vector(wstring) to System::String ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsquestion
4 Posts 3 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.
  • T Offline
    T Offline
    Thilek
    wrote on last edited by
    #1

    hi guys, i been working on a worm scanner lately... i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box. but when i compile there is no problem but when i run it there is problem showing : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Below is my coding : if (ListFiles(directory, L"*", files)) { for (vector<wstring>::iterator it = files.begin(); it != files.end(); ++it) { std::string filename = WStringToString(it->c_str());; std::string s=filename; String ^someString= gcnew String(s.c_str()); listBox1->Items->Add(String::Format(someString,"\n")); // wcout << it->c_str() << endl; } } Kidly help me plz... Regards, Thilek

    C D 2 Replies Last reply
    0
    • T Thilek

      hi guys, i been working on a worm scanner lately... i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box. but when i compile there is no problem but when i run it there is problem showing : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Below is my coding : if (ListFiles(directory, L"*", files)) { for (vector<wstring>::iterator it = files.begin(); it != files.end(); ++it) { std::string filename = WStringToString(it->c_str());; std::string s=filename; String ^someString= gcnew String(s.c_str()); listBox1->Items->Add(String::Format(someString,"\n")); // wcout << it->c_str() << endl; } } Kidly help me plz... Regards, Thilek

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      I suppose you don't need to convert the std::wstring to a std::string before assigning it to a System.String, moreover AFAIK the first argument to String::Format should be the requested format. Anyway you'll eventually get better help in the (Managed) C++/CLI [^] forum. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      T 1 Reply Last reply
      0
      • C CPallini

        I suppose you don't need to convert the std::wstring to a std::string before assigning it to a System.String, moreover AFAIK the first argument to String::Format should be the requested format. Anyway you'll eventually get better help in the (Managed) C++/CLI [^] forum. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        T Offline
        T Offline
        Thilek
        wrote on last edited by
        #3

        okies... thanks a lot ya... i posted there ready.. hope someone help me there.. :)

        1 Reply Last reply
        0
        • T Thilek

          hi guys, i been working on a worm scanner lately... i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box. but when i compile there is no problem but when i run it there is problem showing : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Below is my coding : if (ListFiles(directory, L"*", files)) { for (vector<wstring>::iterator it = files.begin(); it != files.end(); ++it) { std::string filename = WStringToString(it->c_str());; std::string s=filename; String ^someString= gcnew String(s.c_str()); listBox1->Items->Add(String::Format(someString,"\n")); // wcout << it->c_str() << endl; } } Kidly help me plz... Regards, Thilek

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Thilek wrote:

          i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box.

          Why can't you just send the listbox a LB_DIR message?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

          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