Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Casting from std::string to String
Re: Casting from std::string to String [message #50356 is a reply to message #50355] Wed, 03 October 2018 12:54 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello Giorgio,

Vector::push_back is there for STL compatibility, but you don't really need it here. You can simply use Add method, as there is already a constructor (String(const std::string& s)) for conversion.

E.g:

#include <Core/Core.h>
#include <vector>

using namespace Upp;

CONSOLE_APP_MAIN
{
	StdLogSetup(LOG_COUT);
	
	std::vector<std::string> sWords;
	Vector<String> uWords;
	
	for(int i = 0; i < 5; i++)
		sWords.push_back(std::to_string(i));
	
	for(int i = 0; i < sWords.size(); i++)
		uWords.Add(sWords[i]);
	
	for(const auto& s : uWords)
		LOG(s);
}


Best regards,
Oblivion


[Updated on: Wed, 03 October 2018 12:59]

Report message to a moderator

 
Read Message
Read Message
Read Message
Previous Topic: RLOG in Linux
Next Topic: MoveableAndDeepCopyOption inherite to use a VectorMap ?
Goto Forum:
  


Current Time: Sun May 12 12:23:21 CEST 2024

Total time taken to generate the page: 0.02461 seconds