473,386 Members | 1,715 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,386 software developers and data experts.

Find&Replace String!

stealwings
Hello everyone;
Its me again, I was wondering if some one can give me some guidelines about how to Find and replace a string after reading it from a file using i/o commands I mean, I have a file that I opened and read the context of it with the ftream functions shown as below:
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4. #include <fstream>
  5. using std::ifstream;
  6. using std::ofstream;
  7. #include <stdio.h>
  8. #include <cstdlib>
  9. #include <string>
  10. #include <stdlib.h>
  11. #include <iomanip>
  12. #define MAXLENGTH 256
  13. int _tmain(int argc, _TCHAR* argv[])
  14. {
  15.     char MyWord[MAXLENGTH];
  16.     char *MyString;
  17.     ifstream ReadWord;
  18.     ofstream WriteWord;
  19.     ReadWord.open("file.txt");
  20.     WriteWord.open("file.dat");
  21.     if(!WriteWord)
  22.     {
  23.         cerr<<"couldn't create file"<<endl;
  24.         exit(1);
  25.     }
  26.     if (!ReadWord)
  27.     {
  28.         cerr<<"not found"<<endl;
  29.         exit (1);
  30.     }
  31.  
  32.     while(!ReadWord.eof())
  33.     {
  34.         ReadWord.getline(MyWord,MAXLENGTH);
  35.     //    ReadWord>>MyWord;
  36.         MyString=MyWord;
  37.         cout<<MyString<<endl;
  38.     //    WriteWord<<MyString<<endl;    
  39.     }
  40.     ReadWord.close();
  41.     WriteWord.close();
  42.     return 0;
  43. }
  44.  
  45.  
now I want to know how can I find a word or a phrase then replace it with another, I have tried the .fin() function but the compiler tells me that the function must have class/strut/union type, and I don't really know how to do that, my knowledge is really poor in coding, plz some one help me out. Thanks in advance.
Feb 12 '07 #1
2 1537
horace1
1,510 Expert 1GB
as you are using C++ read the information into a string (not a char array) and use the string search and replace functions, see
http://www.cprogramming.com/tutorial/string.html
Feb 12 '07 #2
as you are using C++ read the information into a string (not a char array) and use the string search and replace functions, see
http://www.cprogramming.com/tutorial/string.html
I don't get you, can you be a little bit more specific plz? Thx.
Feb 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mark | last post by:
I'm scratching my head slightly about how to do the following. I have roughly 800 PHP includes in as many directores, 2 levels deep. Inside each include I have the same 2 variables, but with...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
1
by: Daniel Miller | last post by:
Question 1: Is there a pre-made solution for implimenting Find & Replace for a textbox, or will I have to roll my own using String.IndexOf? Question 2: When I right-click on a file -> Open With...
0
by: ApexData | last post by:
I Want Access FIND&REPLACE to stay in FIND mode. Can I place the (Access FIND&REPLACE Dialog) in a popup/modal dialog form? I need to control this process to prevent the user from pressing keys...
2
by: john | last post by:
In a table I have text field A. I would like to replace all the null values in field A to a real value, let's say 'Test'. When I use Find & Replace and I search for 'is null' and I press replace or...
14
by: inpuarg | last post by:
I want to find a & character using Regex. But not && How can i manage this in c# Quickfind window ? -------------------------------------------------- ne kadar yaşarsan yaşa sevdiğin kadardır...
2
by: Nico Grubert | last post by:
Hi there, I have a string containing some hyperlinks. I'd like to replace every hyperlink with a HTML style link. Example: -------- Replace 'http://www.foo.com/any_url' with
3
by: Crash | last post by:
VS2005 In the find/replace dialog if I make a regex like this I can find all of the "New" statements that instantiate a class with "System" in the name: <New>.*<System> But how - in the VS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
jinu1996
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...

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.