i merged files using string but error in line 13

closed account (1vf9z8AR)
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;
}

  
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, '.' );

closed account (1vf9z8AR)
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;
}
You are going around in circles.

Look at lines 30 to 33. Then, re-read this: http://www.cplusplus.com/forum/beginner/223349/#msg1023671
closed account (1vf9z8AR)
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";
What about lines 43 and 44.
closed account (1vf9z8AR)
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.