473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

string transform with different input and output

Is method 2 valid?

Method 1:
wstring input = L"STRING";
wstring output = input;
transform(output.begin(), output.end(), output.begin(), towupper);

Method 2:
wstring input = L"STRING";
wstring output;
transform(input.begin(), input.end(), output.begin(), towupper);

I"m seeing crash under Visual Studio 2003 with method2.

Nov 3 '05 #1
3 2759

edgekaos wrote:
Is method 2 valid?

Method 2:
wstring input = L"STRING";
wstring output;
transform(input.begin(), input.end(), output.begin(), towupper);


No, it's not. The output iterator needs to be the same length as the
input iterator.

Cheers,
Andre

Nov 3 '05 #2
Sorry to reply to my own post, but...

in*****@gmail.com wrote:
edgekaos wrote:
Is method 2 valid?

Method 2:
wstring input = L"STRING";
wstring output;
transform(input.begin(), input.end(), output.begin(), towupper);


No, it's not. The output iterator needs to be the same length as the
input iterator.


OR, you can also use std::back_inserter(). Like so:

string input = "Hello World!";
string output;

transform( input.begin(), input.end(), back_inserter( output ), toupper
);

Cheers,
Andre

Nov 3 '05 #3
edgekaos wrote:
Is method 2 valid?

Method 1:
wstring input = L"STRING";
wstring output = input;
transform(output.begin(), output.end(), output.begin(), towupper);

Method 2:
wstring input = L"STRING";
wstring output;
transform(input.begin(), input.end(), output.begin(), towupper);

I"m seeing crash under Visual Studio 2003 with method2.


The latter method is not valid. In order to make it valid you should either
pre-set the size of the destination string

wstring input = L"STRING";
wstring output(input.length(), 0);

transform(input.begin(), input.end(), output.begin(), towupper);

or use the 'back_insert_iterator' as the output iterator (see 'int2str's
messages), optionally reserving the required amount of memory in advance

wstring input = L"STRING";
wstring output;

output.reserve(input.length()); // <- optional

transform(input.begin(), input.end(), back_inserter(output), towupper);

--
Best regards,
Andrey Tarasevich
Nov 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Patrick Guio | last post by:
Dear all, I am trying to use the std::transform algorithm to to the following vector< vector<char> >::iterator ik = keys.begin(); // key list iterator vector< vector<char> >::iterator is = ik;...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
5
by: z. f. | last post by:
Hi, is there a sample code for a program that accept input xml file name, input xsl file name and output result file name and outputs the resulting xml? TIA, z.
1
by: Mike Hofer | last post by:
I've got two statements in my code that are both generating weird, weird, weird messages: The first one was, Dim document As System.Xml.XmlDocument Dim navigator As...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
6
by: Vijai Kalyan | last post by:
Hello, I am trying to use std::transform to take in a collection of strings, transform them and insert the result into an output container. So, I wrote something like this: std::wstring...
4
by: JJ | last post by:
I need to encrypt credit card # and store that in a database (and be able to decrypt it). Any codes that use strong encyption algorithm like AES 256 on the web that I can copy and paste? Thanks
1
by: patrickbeaudoin | last post by:
Hi, I have a problem when I put the <htmltag in to a xsl transformtion. First, I give you a xml and xsl example: XML: <form title="Test" height="600" width="800"> <element type="check">...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.