Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello all. I am having a small problem here. Im trying to code a text editor in c++ console. I have the majority of it done, but am running into a small problem. I was able to accept input(text), put it into a two-demensional array and store it in a text file. NOw i am on the part where the user will choose a row from the array and edit that line. I am having problems with IFSTREAM, taking in the text file text and displaying it exactly as it appears. I am able to get the text but for some odd reason whenever i enter a space between words, the IFSTREAM output displays this on a new line. I will include the code, any help appreciated.
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>using namespace std;
char text[24][81];
char text1[24][81];
int row,col;
int counter;
int subscript_1; //row
int subscript_2;
int editrow;
int x;
int choice;string end;
int main()
{
start:
system("cls");
cout<<"1.New";
cout<<'\n';
cout<<"2.Edit";
cout<<'\n';
cin>>choice;if(choice==1)
{
system("cls");
ofstream example ("example.txt");cout<<"Type EXIT to quit and save text.";
cout<<'\n';
cout<<'\n';
//prompt
for(subscript_1=0;subscript_1<24;subscript_1++)
{
gets(text[subscript_1]); //row will increment after they hit enter
if(text[subscript_1][0]=='E'&&text[subscript_1][1]=='X'&&text[subscript_1][2]=='I'&&text[subscript_1][3]=='T')
{
cout<<"Data saved to file.\n";
goto start;
}
example<<text[subscript_1]<<endl;//will put text into file
}
example.close();
}
if(choice==2)
{
for(subscript_1=0;subscript_1<24;subscript_1++)
{
if(text[subscript_1][0]=='E'&&text[subscript_1][1]=='X'&&text[subscript_1][2]=='I'&&text[subscript_1][3]=='T')
{
goto edit;
}
puts(text[subscript_1]);
}
}edit: //edit
cout<<"\n\n";
ifstream example2;
example2.open("example.txt",ios::in);
for(subscript_1=0;subscript_1<24;subscript_1++)
{
example2>>text1[subscript_1];
puts(text1[subscript_1]);
}
example2.close();
return 0;
}
//no errors

![]() |
a map on a website
|
Access Parallel Port
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |