trouble parsing tab-delimited text file due to '\n'

I am trying to understand why when I use getline to parse with '\t' it ignores '\n'. I've looked in my books and here and the internet. Can't figure this out. So my file is multi-line tab delimited string file. For each line, there is no tab in first position or the last position, which I believe is standard for text files. I am trying to put the substring into a vector. So getline below gives me the entire line, which I can the cut up using tab. Using getline that is commented out causes the last piece of data in, say line 0, to be included with the first data of line 1. Is there a way to get around this with getline, or do I need to add more code to parse the resulting string?

1
2
3
4
5
6
7
8
9
10
 if (file2_.is_open())	
	while (file2_.good())  
	{  
		string substr;	
		getline(file2_, substr);
		//getline(file2_, substr, '\t');
		cout << "from here]" << substr << "[to here" << endl;
		vec_Forecast_Data_.push_back(substr); 
	}
	file2_.close();
Getline only looks for one specific delimiter, it can be a newline, or tab, or anything else. But not two different characters at the same time.

One approach is to use a getline with the default delimiter of '\n'. Then use a stringstream to parse that with getline and the '\t' delimiter.
1
2
3
4
5
6
7
8
9
10
    string line;
    while (getline(file2_, line))
    {
        istringstream ss(line);
        string substr;
        while(getline(ss, substr, '\t'))
        {
            cout << substr << '\n';
        }
    }

http://www.cplusplus.com/reference/sstream/istringstream/
Thank you. I've settled on the approach you suggest, but I was just thinking I was missing something and that perhaps I could get it to consider two delimiters.
Topic archived. No new replies allowed.