Tuesday, August 8, 2023

doodle c++ vector map pair

//c++ vector, map and pair are kindof like python list, dictionary and tuple. 
#include <iostream> //for cout
#include <vector> //for std vector
#include <map> //for map, pair


int main()
{
	///*
	//std list
	std::vector<std::string> some_strs;
	some_strs.push_back("a_");
	some_strs.push_back("b_");
	
	//looping
	std::vector<std::string>::iterator strIter;
	for(strIter = some_strs.begin(); strIter != some_strs.end(); ++strIter)
	{
		std::cout<< *strIter << std::endl;
	}
	
	//looping another way
	for(unsigned int j=0; j < some_strs.size(); ++j)
	{
		std::cout<< some_strs[j] << std::endl;
	}
	//*/
	
	/*
	//std map
	std::map<std::string, double> adict;
	adict["a"] = 5;
	adict["b"] = 21;
	
	std::map<std::string, double>::iterator adictIter;
	for( adictIter = adict.begin(); adictIter != adict.end(); ++adictIter)
	{
		std::cout<< adictIter->first <<" "<< adictIter->second <<std::endl;
	}
	*/
	
	/*
	//std pair
	std::pair<std::string, std::string> atuple; //could also make with atuple("a","huraay");
	atuple = std::make_pair("a","huraay");
	
	std::cout<< atuple.first <<" "<< atuple.second <<std::endl;
	*/
	
	
	return 0;
}

//to test it
//g++ -o prog share.cpp
//./prog

//inspired by Brian Overland's book C++ for the Impatient
 
for learning c++ i also highly recommend checking out the probability and geometry examples here:
https://github.com/TheAlgorithms/C-Plus-Plus/tree/master/probability

Thanks for looking