473,487 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

string

98 New Member
good after noon, if i give one string the same string will again displayied as output.But here the privious string is gives as output...
sir i want the same string as output please give the correct code...
The code is given below...

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
fstream ofile("string.txt",ios::in|ios::out);
cout<<"\n enter the string";
char str[100],c;
cin>>str;
for(int i=0;str[i];i++)
ofile.put(str[i]);
ofile.seekg(0);
while(ofile)
{
ofile.get(c);
cout<<c;
getch();
}
}
Aug 27 '08 #1
2 1174
arnaudk
424 Contributor
Thare are many things wrong with this code
  1. Did you read the posting guidelines? They're conveniently summarized next to the box where you typed your question: use [code]...[/code] tags around your code.
  2. #include <iostream> not <iostream.h>
  3. #include <fstream> not <fstream.h>
  4. conio.h is non-standard. You don't really need it for what you're trying to do so I would avoid it alltogether
  5. You're missing std:: in many places, or "using namespace std;".
  6. You don't need "put" to write strings to your file. Use << instead.
  7. You don't need "get" to read strings from your file. Use >> instead.
  8. If you really want to use put and get, then you should check a reference for fstream: the beginning of the file is not necessarily at position 0. Use tellp first to get the position of the put pointer before writing to the file. Then seekg to this position after writing to reread the string. Note that the get and put pointers are can be at two different positions, that's why there is a seekg and seekp.
  9. consider using C++ strings if you are using C++ instead of C strings.
  10. You did not close your file.
Aug 27 '08 #2
sicarie
4,677 Recognized Expert Moderator Specialist
sreekandan-

Please check your PM's, accessible under the Network section of the toolbar at the top of this page.

Thanks,

sicarie
Aug 28 '08 #3

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

Similar topics

16
6701
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
31154
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
7985
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
10
8143
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
4754
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
29
4273
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...
2
3159
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
15
50130
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
3033
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
4721
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
7106
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
6967
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
7137
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
6846
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
5442
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,...
1
4874
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
4565
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
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
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.