i merged files using string but error in line 13
Oct 21, 2017 at 6:45am UTC
error:
F:\c++projects\printmerge\printmergefiles.cpp|13|error: no matching function for call to 'std::basic_istream<char>::getline(std::string&, int, char)'|
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
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
void create(string filename)
{
ofstream writefile;
string line;
char ch;
writefile.open(filename);
do
{
cout<<"Enter line(dot to terminate):" ;cin.getline(line,80,'.' );
writefile<<line<<"\n" ;
cout<<endl;
cout<<"Enter more lines?(y/n)" ;cin>>ch;
cout<<endl;
}while (ch=='y' );
writefile.close();
}
void cat(string filename1,string filename2)
{
remove("merge.txt" );
string line;
ifstream file1,file2;
ofstream newfile;
file1.open(filename1);
file2.open(filename2);
newfile.open("merge.txt" );
while (file1>>line)
newfile<<line<<"\n" ;
while (file2>>line)
newfile<<line<<"\n" ;
newfile.close();
file2.close();
file1.close();
}
void readcat()
{
ifstream read;
string line;
read.open("merge.txt" );
while (read>>line)
cout<<line<<endl;
read.close();
}
int main()
{
cout<<"Write your first file" <<endl;
create("file1.txt" );
cout<<"Write your second file" <<endl;
create("file2.txt" );
cout<<"Your merged file" <<endl;
cat("file1.txt" ,"file2.txt" );
readcat();
return 0;
}
Oct 21, 2017 at 6:53am UTC
1 2
// #include<string.h>
#include <string>
And line 13:
/
1 2
/ cout<<"Enter line(dot to terminate):" ;cin.getline(line,80,'.' );
cout<<"Enter line(dot to terminate):" ; std::getline( std::cin, line, '.' );
Oct 21, 2017 at 8:01am UTC
oooooooooooooooooooooh your method worked but every word is in different line instead of every line being in different line.
What did the std:: do?
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
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void create(string filename)
{
ofstream writefile;
string line;
char ch;
writefile.open(filename);
do
{
cout<<"Enter line(dot to terminate):" ;std::getline(std::cin,line,'.' );
writefile<<line<<"\n" ;
cout<<endl;
cout<<"Enter more lines?(y/n)" ;cin>>ch;
cout<<endl;
}while (ch=='y' );
writefile.close();
}
void cat(string filename1,string filename2)
{
remove("merge.txt" );
string line;
ifstream file1,file2;
ofstream newfile;
file1.open(filename1);
file2.open(filename2);
newfile.open("merge.txt" );
while (file1>>line)
newfile<<line<<"\n" ;
while (file2>>line)
newfile<<line<<"\n" ;
newfile.close();
file2.close();
file1.close();
}
void readcat()
{
ifstream read;
string line;
read.open("merge.txt" );
while (read>>line)
cout<<line<<endl;
read.close();
}
int main()
{
cout<<"Write your first file" <<endl;
create("file1.txt" );
cout<<"Write your second file" <<endl;
create("file2.txt" );
cout<<"Your merged file" <<endl;
cat("file1.txt" ,"file2.txt" );
readcat();
return 0;
}
Oct 21, 2017 at 11:14am UTC
Oct 21, 2017 at 7:30pm UTC
i change lines 30 to 33 to this but same error
1 2 3 4
while (getline(file1,line))
newfile<<line<<"\n" ;
while (getline(file2,line))
newfile<<line<<"\n" ;
Oct 21, 2017 at 8:33pm UTC
What about lines 43 and 44.
Oct 21, 2017 at 8:43pm UTC
yaaaay it works perfectly now.
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
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void create(string filename)
{
ofstream writefile;
string line;
char ch;
writefile.open(filename);
do
{
cout<<"Enter line(dot to terminate):" ;std::getline(std::cin,line,'.' );
writefile<<line<<"\n" ;
cout<<endl;
cout<<"Enter more lines?(y/n)" ;cin>>ch;
cout<<endl;
}while (ch=='y' );
writefile.close();
}
void cat(string filename1,string filename2)
{
remove("merge.txt" );
string line;
ifstream file1,file2;
ofstream newfile;
file1.open(filename1);
file2.open(filename2);
newfile.open("merge.txt" );
while (getline(file1,line))
newfile<<line<<"\n" ;
while (getline(file2,line))
newfile<<line<<"\n" ;
newfile.close();
file2.close();
file1.close();
}
void readcat()
{
ifstream read;
string line;
read.open("merge.txt" );
while (getline(read,line))
cout<<line<<endl;
read.close();
}
int main()
{
cout<<"Write your first file" <<endl;
create("file1.txt" );
cout<<"Write your second file" <<endl;
create("file2.txt" );
cout<<"Your merged file" <<endl;
cat("file1.txt" ,"file2.txt" );
readcat();
return 0;
}
Topic archived. No new replies allowed.