Home › Forums › C Programming › Some problems in C++ › Re: Re: Some problems in C++
January 25, 2009 at 7:21 am
#3512
050449
Participant
thanks it works ok.
now code is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <br /> #include <iostream><br /> #include <fstream><br /> #include <string.h><br /> #include <stdlib.h><br /> #define MAX_NAME 1000<br /> <br /> <br /> using namespace std;<br /> char sendtext;<br /> char username;<br /> <br /> void read(){<br /> system("cls");<br /> cout << "You autorised as:" << username << "n";<br /> ifstream in;<br /> in.open("msngr.txt");<br /> if (!in) {<br /> cout << "Input file cannot be opened.n";<br /> //return(1);<br /> }<br /> char str[20000];<br /> while (!in.eof()) {<br /> in >> str;<br /> cout << str << "n";<br /> strcpy(str, "");<br /> }<br /> cout << "n";<br /> in.close();<br /> <br /> }<br /> void write ()<br /> {<br /> <br /> char choice;<br /> cout << "do you want to input data to file ( y or n )" << endl;<br /> cin >> choice;<br /> cin.get(); //get newline<br /> while ( choice != 'y' && choice != 'n' )<br /> {<br /> cout << "bad choice!" << endl;<br /> cout << "do you want to input data to file ( y or n )" << endl;<br /> cin >> choice;<br /> cin.get(); //get newline<br /> }<br /> <br /> if ( choice == 'y' )<br /> {<br /> char inputText [ MAX_NAME ];<br /> cout << "enter input text: " << endl;<br /> cin.getline ( inputText , MAX_NAME , 'n' );<br /> <br /> ofstream outputFile;<br /> //PUT YOUR DATA FILE NAME HERE!<br /> outputFile.open ( "msngr.txt" , ios::app );<br /> outputFile << inputText << endl;<br /> outputFile.close();<br /> read();<br /> write();<br /> }<br /> <br /> }<br /> main(){<br /> cout << "Enter your username: ";<br /> cin >> username;<br /> read();<br /> write();<br /> <br /> <br /> return (0);<br /> }<br /> <br /> </fstream></iostream> |
but there is some problems too.
when i enter username it writes only first the letter of the username and all other letters understands as answer to the confirmation and writes
You autorised as:N
do you want to input data to file ( y or n )
bad choice!
do you want to input data to file ( y or n )
bad choice!
do you want to input data to file ( y or n )
and when it shows the data of the file it puts n after all words and when i write “something is wrong”
it shows
something
is
wrong
but in file everything is ok