Hi,

I have the following examplde code.

// TestProject.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "TestProject.h"
#include <iostream>
#include <vector>
#include <windows.h>

#define UNICODDE

using namespace std;

int main(void)
{
    CString test;


	  std::vector<std::vector<CString> > your2darray;

    std::vector<CString> row;
    row.push_back("col 1.1");
    row.push_back("col 1.2");
    row.push_back("col 1.3");
    
    your2darray.push_back(row); // push 1 row in the matrix
    row.clear();

    row.push_back("col 2.1");
    row.push_back("col 2.2");

    your2darray.push_back(row); // push 1 row in the matrix
    row.clear();
    
    row.push_back("col 3.1");
    row.push_back("col 3.2");
    row.push_back("col 3.3");
    row.push_back("col 3.4");
    
    your2darray.push_back(row); // push 1 row in the matrix

    for (unsigned y = 0; y < your2darray.size(); ++y)
	{
        for (unsigned x = 0; x < your2darray.at(y).size(); ++x) 
		{
            test = your2darray.at(y).at(x);
			std::cout << test.GetBuffer(0) << " | ";
        }
        std::cout << '\n';
    }
    return 0;
}

Is there an easy way to assign a new CString to an existing element in the array. For example, I would like to replace
" your2darray.at(0).at(0) " which contains the CString ("col 1.1") with ("TEST THIS").

Cant seem to get it right? Any help will be appreciated.

Thanks!

Did you try your2darray[y][x] = "Hello"; or this?

vector<CString>& s = your2darray[y];
s[y] = "Hello";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.