Thread: while does this 2d char array (almost) work in C , but not even close in C++?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    Do you realize that your C++ version is no longer doing the same thing as the C version, even if you fix the logic errors in the C version?
    I have no idea how it works under the hood. I only know it is now acting like a 1d array because one no longer has to reference both whatever them [ ] <<--- are called.

    Code:
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    int main()
    {
        vector < string > snackos =
            { " ", "Cracker Jacks","Gummy Bears","Lemon Heads",
            "Skittles","Snickers","Milky Way"};
    int count = 1;
    
    for ( ; count < 7 ; count++)
        cout <<snackos[count]<<endl;   
        cout<<"\n"<<snackos[4]<<endl;
    
        //last line prints out the 5th element starting from  zero,
        // after the loop has ened. 
        //Is it properly placed within the code?
        // Some would say no. But the compiler won't complain about it as
        //much as some humans might.
    return 0;
    }
    that much I know.
    Last edited by userxbw; 12-16-2017 at 03:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning a char value to char pointer doesn't work.
    By inckka in forum C Programming
    Replies: 5
    Last Post: 03-15-2017, 04:34 AM
  2. Replies: 2
    Last Post: 09-25-2014, 06:12 AM
  3. Replies: 2
    Last Post: 09-25-2014, 04:03 AM
  4. Help altering code to work with char array
    By mikeman in forum C++ Programming
    Replies: 3
    Last Post: 02-16-2010, 07:59 PM
  5. Replies: 3
    Last Post: 11-17-2008, 12:36 PM

Tags for this Thread