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. Managed C++/CLI
  4. for each loop

for each loop

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
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
    teejayem
    wrote on last edited by
    #1

    I know this sounds like a stupid question but i can't seem to get a for each loop to compile correctly. I tried...

    for each (IpAddress ^addr in ipAddresses) {
    
    }
    

    and...

    IpAddress^ addr = nullptr
    for each (addr in ipAddresses) {
    
    }
    

    but none of them compile. I know i could do a for loop but i would rather just do a for each. I searched but i cant seem to find anyone else having this problem. Thanks alot for any help here are some of the errors:

    Error 1 error C2143: syntax error : missing 'in' before '^'
    Error 2 error C2065: 'addr' : undeclared identifier
    Error 3 error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)

    Don't be overcome by evil, but overcome evil with good

    G 1 Reply Last reply
    0
    • T teejayem

      I know this sounds like a stupid question but i can't seem to get a for each loop to compile correctly. I tried...

      for each (IpAddress ^addr in ipAddresses) {
      
      }
      

      and...

      IpAddress^ addr = nullptr
      for each (addr in ipAddresses) {
      
      }
      

      but none of them compile. I know i could do a for loop but i would rather just do a for each. I searched but i cant seem to find anyone else having this problem. Thanks alot for any help here are some of the errors:

      Error 1 error C2143: syntax error : missing 'in' before '^'
      Error 2 error C2065: 'addr' : undeclared identifier
      Error 3 error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)

      Don't be overcome by evil, but overcome evil with good

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      teejayem wrote:

      here are some of the errors:

      And what are the other errors? Sometimes some errors are caused because of the errors that occur before them. I guess these are errors for the first case. Your code should look like this: foreach (IpAddress^ addr in ipAddresses) { }

      #region signature my articles #endregion

      T 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        teejayem wrote:

        here are some of the errors:

        And what are the other errors? Sometimes some errors are caused because of the errors that occur before them. I guess these are errors for the first case. Your code should look like this: foreach (IpAddress^ addr in ipAddresses) { }

        #region signature my articles #endregion

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

        hey Giorgi thanks for your reply. these are some of the errors i get. Error 1 error C2143: syntax error : missing 'in' before '^' Error 2 error C2065: 'addr' : undeclared identifier Error 3 error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)

        array^ ipAddresses = Dns::GetHostAddresses(Dns::GetHostName());
        for each (IpAddress ^addr in ipAddresses) {
        
        }
        

        i don't think it is any other part of the code that is failing because as soon as i comment the for each loop it compiles fine. Thanks, -- modified at 9:43 Thursday 11th October, 2007

        Don't be overcome by evil, but overcome evil with good

        L 1 Reply Last reply
        0
        • T teejayem

          hey Giorgi thanks for your reply. these are some of the errors i get. Error 1 error C2143: syntax error : missing 'in' before '^' Error 2 error C2065: 'addr' : undeclared identifier Error 3 error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)

          array^ ipAddresses = Dns::GetHostAddresses(Dns::GetHostName());
          for each (IpAddress ^addr in ipAddresses) {
          
          }
          

          i don't think it is any other part of the code that is failing because as soon as i comment the for each loop it compiles fine. Thanks, -- modified at 9:43 Thursday 11th October, 2007

          Don't be overcome by evil, but overcome evil with good

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          arraySystem::Net::IPAddress^^ ipAddresses =
              System::Net::Dns::GetHostAddresses(System::Net::Dns::GetHostName());
          for each(System::Net::IPAddress^ addr in ipAddresses)
              System::Console::WriteLine( addr->ToString());

          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