   ifstream and how txt files store newlines
  I am storing a bunch of words deliminated by newlines from a text file using ifstrem, but when I read and assign all the words into on concatenated string, it doesn't include the "/n" (newline). I want to be able to know where the newlines are so I can break up this concatenated string into a vector<string>, but I don't know how I would do this. 1:Are txt files created with some delimited form like Text File (comma-delimited); is their a Text File (newline-delimited) varible stored in txt files? 2: Also, is their a way to access the information text files newline "/n" info and is their an easier way via a streaming libary like boost::file_systems or something?Thanks so much!   
  First, it's '\n'.  Not '/n'.  Second, I have absolutely no idea what either of your questions are saying.  What have you tried (i.e. what code are you using), and what exactly is your problem/questions (you'll have to clarify your questions, I just don't understand what you're saying).  If I were trying to read the file:MyTextFile.txtHelloWorldOneWordPerLinePleaseThanks!I'd do something like this:MySourceFile.cppstd::ifstream file("MyTextFile.txt");std::vector<std::string> myVector;std::string myConcatenatedString;while (file.good()){    string str;    std::getline(file, str);    myConcatenatedString += str + '\n';    myVector.push_back(str);|That shows you how to read in one line at a time, and add each line to both a std::vector<string> and a concatenated string (with '\n' between each word).   ;  Would something like this work? or would file.getline(&string,255,'/n') not work since '\n' is a charcter defined as a replacement for newline and the concat_word doesn't even store \n. Pluse, the txt file may not store newlines like /n. I know it doesn't directly store it in the file, hence, it was't read from the ifstream!ifstream file;file.open("words.txt");std::string concat_word;// concatenate all the words in txt file to concat_word// seperated wordsvector&lt;std::string&gt; words;char *string;file.getline(&string,255,'\n')words.push_back(*string); [Edited by - Mad_Coder on June 12, 2009 4:16:28 PM];Quote:Original post by Mad_CoderI am storing a bunch of words deliminated by newlines from a text file using ifstrem, but when I read and assign all the words into on concatenated string, it doesn't include the "/n" (newline). I want to be able to know where the newlines are so I can break up this concatenated string into a vector<string>, but I don't know how I would do this.What function(s) are you using to read the file? All functions intended to read a single line from the file will skip the trailing newline character. The simplest solution to this problem would be to read the lines directly into the std::vector.However, if you are reading multiple lines (or the whole file) in one call, then it is possible that you are reading in binary mode (i.e. with newline translation disabled), and your platform doesn't represent newlines as '\n'. The solution to this problem is to open the file in text mode.A simple C++ program to accomplish this task looks something like this:#include <string>#include <fstream>#include <vector>std::ifstream input("input.txt");std::vector<std::string> result;while (input) {std::string line; std::getline(input, line);result.push_back(line);}Though the idiomatic approach is a little shorter:std::ifstream input("input.txt");std::vector<std::string> result;std::copy( std::istream_iterator<int>(input), std::istream_iterator<int>(), std::back_inserter(result) );;  Thanks, that's what I was asking, but I don't understand two other things, How does the txt file store newlines, since '\n' characters aren't read via ifstream objects? And why doesn't it read the newline characters via ifstream if getline() can read the newline deliminator by defualt if you do not specify a different delim parameter ?   ;Quote:Original post by Mad_CoderThanks, that's what I was asking, but I don't understand two other things, How does the txt file store newlines, since '\n' characters aren't read via ifstream objects? And why doesn't it read the newline characters via ifstream if getline() can read the newline deliminator by defualt if you do not specify a different delim parameter ?It stores them.  The '\n' characters are there.  The input stream reads the newline characters.  But it ignores them and doesn't give them to you.  Why?  Because you aren't asking for them.  If you were to read the raw data, you'd get the '\n' characters.  But I'm guessing you're using either operator >> or getline, both of which will skip the '\n' character (because the '\n' character tells them when to stop reading, so they use it as a special marker character, which they then discard).Oh, and just so you know, GameDev [code] tags are lower case.   ;Quote:Original post by MikeTacularQuote:Original post by Mad_CoderThanks, that's what I was asking, but I don't understand two other things, How does the txt file store newlines, since '\n' characters aren't read via ifstream objects? And why doesn't it read the newline characters via ifstream if getline() can read the newline deliminator by defualt if you do not specify a different delim parameter ?It stores them.  The '\n' characters are there.  The input stream reads the newline characters.  But it ignores them and doesn't give them to you.  Why?  Because you aren't asking for them.  If you were to read the raw data, you'd get the '\n' characters.  But I'm guessing you're using either operator >> or getline, both of which will skip the '\n' character (because the '\n' character tells them when to stop reading, so they use it as a special marker character, which they then discard).Also, for completeness, the newlines may not actual be stored as '\n' on disk. Different operating systems have different conventions for storing newlines, including "\n", "\r" and "\r\n". However, when you open a file in text mode (the default for ifstreams), the std::library will automatically translate these to '\n'.   ;Quote:Original post by swiftcoderAlso, for completeness, the newlines may not actual be stored as '\n' on disk. Different operating systems have different conventions for storing newlines, including "\n", "\r" and "\r\n". However, when you open a file in text mode (the default for ifstreams), the std::library will automatically translate these to '\n'.I just want to point out (mostly to Mad_Coder) that that depends on how he's writing the file.  But yes, if he's writing the file in a text-editor (or some other way where the output is being formatted) then you're absolutely correct.   ;  Thanks that made it a lot clearer.   ;  Try to find yourself a hex editor and use it to look at a text file. It might clear some things up for you. :)   