remove _ from input file

Hi how are you all , i have an input files that contains string like this
===========================================================
input.txt
03_20_18
6B_20_15
0B_20_12
6F_20_0F
77_20_0C
07_20_09
1B_20_06
2B_20_03
0F_20_03
00_00_01
------------------------------------------------------------------
My question is how to delete _ (underscores) and the output is the numbers without _ (underscores)
thanks
read from the file into a string.

loop through the string character by character .for( int i = 0, i < string.size(); i++ )
if string[i] != '_' add character to output.
Do you need the values of the numbers or do you just need to output the proper characters back to the screen?

In the first case you would need to convert the text to an integer value. In the second case, you can handle the data strictly as text.
acctually i want these steps :
1-delete _ (underscores).
2-convert file to hexa and binary.
3-print file with hexa and binary.

note: the input file is in hexa
ok i tried your advices and know its work , but still have a problem in printing out

i want to print like this
-----------------------------------------------------------------------------------------------------
032018
6B2015
0B2012
6F200F
77200C
072009
1B2006
2B2003
0F2003
000001
_________________________________________________________________-
here is my code

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
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
#include<cmath>

using namespace std;


int main()
{
	
	ifstream infile;
	infile.open("input.txt");
	if (infile.fail())
	{
		cout << "The file doesn't open" << endl;
			exit(1);
			infile.close();
	}

	string line;
	while (!infile.eof())
	{
		infile >> line;
		for (int i = 0; i <= line.size(); i++)

		
			if (line[i] != '_')
		
			
				cout << line[i];
			
		
	}
	
	return 0;
}


my code is print like this
----------------------------------------------------------------------------------------------
032018 6B2015 0B2012 6F200F 77200C 072009 1B2006 2B2003 0F2003 000001

---------------------------------------------------------------------------------------------

again thank u all for helping
ooooooooooooh know i remeber what should i do
hhhhh i forget to put cout<<endl;

but still have the problem to convert these string to binary
Last edited on
Topic archived. No new replies allowed.