473,466 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

command way for string manipulation?

Hi ng,

could you tell me whats the common way to manipulate Strings in C/C++.
I'm a little bit confused, 'cause there are too many ways to do it ;-)

In my example i would like to open a file, replace 'Keyword1' with
'Keyword2' and save it to another file.
I'm using MS Visual C++ Toolkit (Commandline only).

When i use:
1) char[]: I've no adequate String operations
2) string: I've no '<<'-Operator for writing via 'cout' to my file
3) CString: I don't have the Class/Headers

Which way would a c/c++ take to have a runable programm under the most
common c/c++ compilers?

thanks & best regards,
Stefan

Oct 10 '05 #1
9 1446

<st***************@gmx.de> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi ng,

could you tell me whats the common way to manipulate Strings in C/C++.
I'm a little bit confused, 'cause there are too many ways to do it ;-)

In my example i would like to open a file, replace 'Keyword1' with
'Keyword2' and save it to another file.
I'm using MS Visual C++ Toolkit (Commandline only).

When i use:
1) char[]: I've no adequate String operations
2) string: I've no '<<'-Operator for writing via 'cout' to my file
3) CString: I don't have the Class/Headers

Which way would a c/c++ take to have a runable programm under the most
common c/c++ compilers?


Are the keywords the same length?
Oct 10 '05 #2
st***************@gmx.de wrote:
could you tell me whats the common way to manipulate Strings in C/C++.
I suppose that the most common way would be to use 'std::string' class.
I'm a little bit confused, 'cause there are too many ways to do it ;-)
The usual way out of such confusion is to choose one and stick to it.
In my example i would like to open a file, replace 'Keyword1' with
'Keyword2' and save it to another file.
OK. Open a file, read it into, say, a vector of strings, search for
"Keyword1" in them, replace it if found, then write that vector of
strings into another file.
I'm using MS Visual C++ Toolkit (Commandline only).
That matters not.
When i use:
1) char[]: I've no adequate String operations
Really? What would be "adequate"?
2) string: I've no '<<'-Operator for writing via 'cout' to my file
What do you mean by that?
3) CString: I don't have the Class/Headers
Yes, that's MFC, which probably costs money to get.
Which way would a c/c++ take to have a runable programm under the most
common c/c++ compilers?


I'd still use 'std::string'. Whatever problems you have with writing it
out, post your code, we can help.

V
Oct 10 '05 #3
Hi,

@pemo: No, Strings are not the same length

@Victor:
- An adequate String-operation would be
myString.replace("Keyword1","Keyword2")

Ok let's take std::string
But then my compiler is claiming that my std::string object has no
'<<'-Operator to push the String to the cout-stream... ;-(

(Sorry that i'm going on your nerves with such simple questions, but
the first steps are sometimes the most annoying ones)

Oct 10 '05 #4
st***************@gmx.de wrote:
@Victor:
- An adequate String-operation would be
myString.replace("Keyword1","Keyword2")
You should be able to roll your own with help of 'find', 'erase', and
'insert'. It's called "programming".
Ok let's take std::string
But then my compiler is claiming that my std::string object has no
'<<'-Operator to push the String to the cout-stream... ;-(


What's a 'String'? It definitely not a standard class. Please post
the minimal complete code which causes your compiler to output that
message.

V
Oct 10 '05 #5
st***************@gmx.de wrote:

Hi ng,

could you tell me whats the common way to manipulate Strings in C/C++.
I'm a little bit confused, 'cause there are too many ways to do it ;-)

In my example i would like to open a file, replace 'Keyword1' with
'Keyword2' and save it to another file.
I'm using MS Visual C++ Toolkit (Commandline only).

When i use:
1) char[]: I've no adequate String operations
2) string: I've no '<<'-Operator for writing via 'cout' to my file
You don't write to a file through cout. You write through a file stream
object. And just like any other output stream object there is a << operator
that writes std::string's.

3) CString: I don't have the Class/Headers

Which way would a c/c++ take to have a runable programm under the most
common c/c++ compilers?

thanks & best regards,
Stefan

--
Karl Heinz Buchegger
kb******@gascad.at
Oct 10 '05 #6
st***************@gmx.de wrote:
But then my compiler is claiming that my std::string object has no
'<<'-Operator to push the String to the cout-stream... ;-(


do you remember to:
#include <string>
#include <ostream>

?
B.

Oct 10 '05 #7
st***************@gmx.de wrote:
Hi ng,

could you tell me whats the common way to manipulate Strings in C/C++.
I'm a little bit confused, 'cause there are too many ways to do it ;-)

In my example i would like to open a file, replace 'Keyword1' with
'Keyword2' and save it to another file.
I'm using MS Visual C++ Toolkit (Commandline only).

When i use:
1) char[]: I've no adequate String operations
2) string: I've no '<<'-Operator for writing via 'cout' to my file
That's because you have forgotten to include the right header <string>.
Or you are including <iostream.h> instead of <iostream>, or <fstream.h>
instead of <fstream>, or some such header file problem. Of course you
can output a string to a file with << in C++.
3) CString: I don't have the Class/Headers

Which way would a c/c++ take to have a runable programm under the most
common c/c++ compilers?
There is no language called C/C++, for C choose option 1, for C++ choose
option 2, never choose option 3.

thanks & best regards,
Stefan


john
Oct 10 '05 #8
thanks,
the problem was just including
<string.h>
instead of
<string>

AAAAAAAAAARGH!!

Oct 11 '05 #9
st***************@gmx.de wrote:
thanks,
the problem was just including
<string.h>
instead of
<string>

AAAAAAAAAARGH!!


That'll teach ya! :-) This is a very simple rule: no C++ standard headers
have '.h' after the name. None. Whatsoever.

V
Oct 11 '05 #10

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

Similar topics

4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
5
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or ...
4
by: magix | last post by:
Dear Guru, I'm not so good in file manipulation, but would like to seek for help here. I have following basic code of command line argument as starting point (the code below output the...
7
by: google | last post by:
I would like to execute a single JavaScript command from within a web service. The command is a mathmatical statement. I have a web page with some client side logic that does this and I'm now...
0
by: mbenedict | last post by:
I am rather new at this code and am attempting to modify existing code to use clob datatypes, which I have never used before. The database tables have been set up for clob data. When trying to use...
12
by: Atropo | last post by:
Hi all. Having several strings how do i combine them to construct a command; lets say to run the date command. string str = "14/10/08 19:06:09"; strDD = str.substr(0,2); strMM =...
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
marktang
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,...
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,...
1
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...
0
agi2029
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,...
0
isladogs
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.