User forced next line

Novice programmer reporting in
For the last three weeks I have been trying to make a small program that I will be using in a larger program that will make the user press space to see the next line of output.
Not exactly sure what I'm doing wrong, but I'm pretty sure that I need to put the space that the user would enter into an output file, and the read the input file
It runs, but it doesn't allow me press space before showing the next line.
I added a getline(cin, charVar) before, but I got a whole bunch of errors.
Any help would be greatly appreciated.



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
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <fstream>
using namespace std;

// function for dialouge
//void ContinueDialouge(char);

int main()
{

string filename = "dialouge.txt";
char charVar;
ofstream outFile;
ifstream inFile;

outFile.open(filename.c_str());

if (outFile.fail())
{
  cout << "Error occured when starting dialouge process" << endl;
  exit (1);
}

cout << "This is the first line."; // Press space
outFile.seekp(0L, ios::end);
outFile.put(charVar);
outFile.close();

inFile.open(filename.c_str());
if (inFile.fail())
{
  cout << "Error occured when ending dialouge process." << endl;
  exit(1);
}

inFile.seekg(0L, ios::end);
inFile.get(charVar);
if (charVar = ' ')
  cout << endl;
  
cout << "This is the second line."; 

return 0;

}
I am very new to C++ myself and not very familiar with in/outFile but as far as i can tell right now you don't have anyway for the user to input anything it just runs and closes.


I'm not sure if this will be of any help, but here is a poorly coded user forced next line code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <istream>

using namespace std;

int main() {

 string input = "";

string space;
cout << "This is the first line ";
getline (cin, space);
cout << "This is the second" << space << "line.\n";
cout << "\n";
cin.get();

return 0;
}

.
What is the
string output
for?
I have not had to chance to try this out, but Blanchy I'm going to try this.

Smarty, are you talking about my code or Blanchy's?
Just to let you guys know I kind of fixed it.
It's not as complex as I wanted it to be but it works.
Here it 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
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <fstream>

using namespace std;

// function for dialouge
char GetSpace(char);

int main ()
{

  char space;

  cout << "This is the first line";
  cin.get(space);
  GetSpace(space);
  cout << "This is the second line";
  cin.get(space);
  GetSpace(space);
  cout << "This is the thrid line";
  cin.get(space);
  GetSpace(space);

  return 0;

}

//Function headers
char GetSpace(char getspace)
{
  if (getspace == ' ')
  {
    cout << endl;
  }

  return 0;
}


Also will work if I only press enter instead of space then enter.
Topic archived. No new replies allowed.