Trouble with std::getline()

I'm having trouble trying to figure out how to get this code to read past the space character and the entire way to a new line character. The code I have now works well when I have many changes to make because I can keep up with the output more efficiently and concatenate everything later. But now my changes are getting to be too minute and this method has become time consuming and tedious. I've used the std::getline() function before without trouble but I can't seem to get it working with this code. The code below is only one example (the first) of what I've tried.
example of my task.
input : REGULATOR #X-XXXX TRIPCOIL MONITOR
to
output : REGULATOR #X-XXXX TRIP COIL MONITOR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <iomanip>
#include <set>


int main()
{
	const char* name_file = "Equipment names.txt";
	const char* corrected_name_file = "Corrected equipment names.csv";

	std::ifstream in(name_file);

	if (!in.is_open())
	{
		std::cout << "Unable to open \"" << name_file << "\" for input.\n";
		return 0;
	}

	std::ofstream out(corrected_name_file);

	if (!out.is_open())
	{
		std::cout << "Unable to open \"" << corrected_name_file << "\" for output.\n";
		return 0;
	}

	std::map<std::string, std::string> sanitizedName =
	{
		{ "XFMR (A) SUPV C.O.", "XMFR A SUPERVISORY CONTROL CUTOUT SW" }
	};

	std::string token;
	while (in >> token)
	{
		auto it = sanitizedName.find(token);
		if (it != sanitizedName.end())
			token = it->second;
		out << std::getline (out,token) << '\n';
	}
}
Last edited on
Topic archived. No new replies allowed.