By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

how do i read words like "can't" using getline and keep the apostrophe?

P: n/a
I have a text file that I'm trying to parse with ifstream getline function. The problem is that I have to recognize single quotes in the middle of words as well as on the end of words.

the first line of inputFile.txt is:
'In''''put 'directory: sample/
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     char str[4096];
  4.     ifstream inFile;
  5.     inFile.open("inputFile.txt");
  6.     inFile.getline(str, 4096);
  7.     cout << str << endl;
  8.     inFile.close("inputFile.txt")    
  9.     return 0;
  10. }
  11.  
Getline automatically throws out the single quotes but I don't want it to:
Oct 9 '10 #1
Share this Question
Share on Google+
1 Reply


100+
P: 687
Given that ifstream::close doesn't accept string and there must be semicolon after function call, I guess the program doesn't even compile. An no, it doesn't remove quotes.
Oct 9 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.