Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used getline function BUT it is not working...Please Help..Ckeck this Code below:
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>

using namespace std;

class notepad
{
    string A;

public:

     void newnotpad()
    {
        char name[100];
        cout<<"Enter Name/Path of File: ";
        cin>>name;
        cout<<endl;
        cout<<"Enter Text to New Notepad: "<<endl<<endl;
        getline(cin,A);
        myfile.open(name);
        myfile<<A;
        myfile.close();
    }

};

int main()
{
    notepad x;
    x.newnotpad();
}
Posted
Updated 6-Jun-14 4:05am
v2
Comments
_Asif_ 6-Jun-14 8:14am    
is this <big> part of the code or you have mistakenly add a code while pasting @ codeproject?
Stefan_Lang 6-Jun-14 8:51am    
My guess it was a (failed) attempt to emphasize the problematic line of code. Unfortunately, < and > are part of the C++ language and don't mix well with HTML tags. ;-)
Crack-Mind-Coder 6-Jun-14 10:07am    
Please check now...I have edit that mistake...you should run this code by yourself then you will know the problem....Thanks...!
Crack-Mind-Coder 6-Jun-14 10:07am    
Please check now...I have edit that mistake...you should run this code by your self then you will know the problem....Thanks...!

1 solution

Try adding
C++
cin.ignore();
immediately after
C++
cin >> name;

(see here[^])
 
Share this answer
 
Comments
Stefan_Lang 6-Jun-14 8:52am    
Cool, I wasn't even aware of that. Have a 5.
Crack-Mind-Coder 6-Jun-14 10:16am    
It worked...Thanks...!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900