Files

I have been trying to get this part of my code to work for over an hour. The program is supposed to get a sentence from the user, and write it to the file "meetingNotes.txt". When i run the program it doesn't allow the user to input anything. I think the problem is the getline, but i can't figure out why. Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
    string notesInput;
    ofstream notes;
    notes.open ("meetingNotes.txt");
    cout << "Type Notes Below" << endl;
    getline(cin,notesInput);
    notes << notesInput;
    notes.close();

    return 0;
}
Last edited on
add

using namespace std;
What's the problem? A compilation error? A run-time crash? Something else?

How can we help you if you don't give us information?
You have no std, just add using namespace std;
sorry just forgot to add the using namespace std; when i was taking this part out of the full code. Still doesn't work though.
I just tested it, and it works fine for me. What errors are you receiving, if any?
James3NV wrote:
Still doesn't work though.


MikeyBoy wrote:
What's the problem? A compilation error? A run-time crash? Something else?

How can we help you if you don't give us information?
It works for me,and i cannot see any bugs there,well
sometimes IDE goes mad about "getline(cin,*variable*)"
Try changing getline with cin
so like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
    string notesInput;
    ofstream notes;
    notes.open("meetingNotes.txt");
    cout<<"Type notes below:"<<endl;
    cin>>notesInput;
    notes.close();
}
Last edited on
Topic archived. No new replies allowed.