Pages

Tuesday, April 22, 2025

Char Array (for each loop) in C++

#include <iostream>

#include <cstring>

using namespace std;



int main()

{

    string str = "apna college";

    

    

    // for(int i=0; i<str.length(); i++) {

    //     cout << str[i] << "-";

        

    // } cout << "\n";

        

        for(char ch : str) {

            cout << ch << ",";

        } cout << endl;

    

    // for(char ch : str) {

    //     cout << ch << ",";

    // }

    // cout << endl;


    return 0;

}

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...