Linux - MobileThis forum is for the discussion of all topics relating to Mobile Linux. This includes Android, Tizen, Sailfish OS, Replicant, Ubuntu Touch, webOS, and other similar projects and products.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello everyone
please help me with the following code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream fin;
fin.open("data", ios:: out);
string str;
cin >> str;
fin << str;
fin.close();
fin.open("data", ios::in);
while(fin) {
fin.get(ch);
cout << ch;
}
return 0;
}
if the input is : priya
the output should be priya
but my code is showing the output as priyaa
please help me to sort out the problem with the above code
ohh thank you so much . Now its working properly. But will you please say me what is the difference. And also have a look at this code
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream fin, fin1;
fin.open("copy", ios :: out );
int n;
string str;
cout << "enter no of lines" << endl;
cin >> n;
int i = 0;
do {
getline( cin, str );
fin << str << endl;
i++;
}
while ( i < n );
fin.close();
return 0;
}
In this code i am entering 5 lines but it is taking only 4 lines as input. can u please help me in this case also.what is my wrong here??
Last edited by priya sweet; 09-23-2012 at 06:23 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.