Hello,
Can I convert the entire content of an array into a string?
for example
array[i] = contains the value of {h, e, l, l, o}
I need to complare the entire value with something else not just the last
value (o)
array[i] == string;
Thanks,
Jc 3 2673
"JC" <ke****@secret. com> wrote... Can I convert the entire content of an array into a string?
What array?
for example array[i] = contains the value of {h, e, l, l, o}
How is 'array' declared?
I need to complare the entire value with something else not just the last value (o)
array[i] == string;
Have you tried
string == array
?
Read FAQ 5.8. FAQ is here: http://www.parashift.com/c++-faq-lite/
Victor
"JC" <ke****@secret. com> wrote in message news:9_******** ************@co mcast.com... Hello, Can I convert the entire content of an array into a string?
for example array[i] = contains the value of {h, e, l, l, o}
What is array? The above is NOT any sort of proper definition.
I need to complare the entire value with something else not just the last value (o)
Where did this array come from? What have you tried so far. The trivial case
is as follows.
char array[] = { 'h', 'e', 'l', 'l', 'o' }; // 5 element array with hello in it.
string str(array, sizeof(array)); // string initialized with the array.
if(str == "hello") { ...
JC wrote: Hello, Can I convert the entire content of an array into a string?
Yes. Each element must be transformed into either a string or
a character, then appended to the string (you didn't specify
the type of the array).
for example array[i] = contains the value of {h, e, l, l, o} I need to complare the entire value with something else not just the last value (o)
If the array is an array of characters, you could always complare [sic]
each element of the array with an element of the string:
string hello_string("h ello");
const char * hello_c_string = "hello";
[1] if (array[0] == hello_string[0])
...
if (array[0] == hello_c_string[0])
... array[i] == string;
You can only compare an element of an array to a string if the
each element of the array is a string:
string many_strings[400];
string hello_string("h ello");
if (many_strings[0] == hello_string)
....
If you want to compare arrays of characters to C-Style strings
{which are arrays of characters with a NUL ('\0') character
at the end} there are many functions to help you:
strcmp() -- both parameters must be C-style strings.
strncmp() -- useful for arrays of characters or C-Style strings.
std::string::c_ str() -- Useful for converting an std::string
into a C-style string.
By far, the easiest method for handling text is to use the
std::string class. This class overloads the equality operator
(==) (as well as other operators) for comparing strings:
string hello_string("G uten Tag");
string world_string("W elt");
if (hello_string == world_string)
See the FAQs below for more helpful information.
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will |
last post by:
Hi,
Sorry to be a pest...
But I can figure this out.
I'm pushing to a stack. then I need to check to see if the word is a
palindrome.
Is the code below correct?
if so, how can I check the entire word?
|
by: Frank Rizzo |
last post by:
Hello, doing some profiling work and trying to resolve the memory usage
balooning through the roof. Just want to make sure that my reasoning is
correct.
My question is as follows: Let's say I have 1000 ArrayLists and each of
them has quite a bit of data in them. Does .NET framework load 1000
implementations of ArrayList in memory or does it load just one and uses
that to operate on data in the lists?
Thanks.
|
by: LedZep |
last post by:
This program has to use a stack to determine whether a
string is a palindrome (a string that is spelled identically backward
and forward). The program has to ignore spaces, case sensitivity and
punctuation. I have to somehow take the input from the txtbox, stack
it letter by letter onto a stack, then display it written forward and
below it written backwards. I understand the concept of stacks -- I
just need a little push in the right...
|
by: Rich Kucera |
last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version
configurations inevitable
Will have to wait to see what the impact of problems such as
http://bugs.php.net/bug.php?id=33643 to the application world. We may
wait for a suitable popular resolution and jump to that version in the
future. There's already a rift between PHP4 and PHP5, and then further
developments such as these create another, splitting the camp into 4....
|
by: Daniel |
last post by:
Hi,
I have a question regarding the memory managment in stl stacks. I want
to use stacks to store a very large amount of numbers (some millions),
thus I'm interested in how the stack behaves when it has to increase
its memory.
http://www.sgi.com/tech/stl/stack.html, the stacks default underlying
container is a deque that has amortized constant time insertion and
removal of elements.
| |
by: chubbykelly |
last post by:
hi, i got a prob with the new topic my teacher in data struct taught us
this afternoon. he introduced the concept of stacks. simulated how 5
elements will be pushed and popped out to the array elements and arrange
them in ascending order. but he did not show the c program for it. i
want to learn how to program it. can u help me with this please?
thanks,
kelly
|
by: raghuveer |
last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have
#include<stdio.h>
#include<conio.h>
int top;
int bot;
void main()
{
|
by: MLH |
last post by:
Suppose you needed to print a large number of consecutively
numbered documents the size of a post-card ==or perhaps even
a business card using a laser printer and 60# bond. Suppose you
planned to print them on a ream of 8.5 by 11 or 14 stock and take
them to the office store for later cutting.
It would be nice if the paper cutter could produce your finished
product - say 4, 8, 12 or more individual stacks of cards, rubber
banded &...
|
by: Mhel |
last post by:
I'm really having a hard time with Stack...
The problem goes this way:
Create an array ( a ).
If choice == 1, push number.
If choice == 2, pop number,
If choice == 3, display stack.
If choice == 0 quit.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |