input file into vectors?

noob at c++










---------------------- TL;DR
http://www.cplusplus.com/forum/beginner/100291/
---------------------------------------
I think I solved my problems in this thread.
Thanks to anyone who read it.

---------------------------------------------------------------
Suppose I have this vector it contains dates example

Vector.Dates [slot 1][slot 2] [slot 3] etc...

anyways slot 1 contains [ 05282013]
slot 2 contains [07032015]

I want to split the data it contains into 3 other locations How do I do that???

like vector.1[05][07]
vector.2 [28][03]
vector.3[2013][2015]

How do you only take partial data from a vector slot?

Thanks!, any help will be appreciated.

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



Ignore post below






I still need help with problem 3, can someone give me link on how to only take partial data stored in vectors?
--------------------------------------------------------------------------------------

Problem 3) ( taking only first 2, last 4, and 3rd,4th digits)

similar to problem 2, only now when I store the integers into a vector ( assuming I get help and fix problem 1 and 2) it would look like this

Vector dates slot 1 [03152019] slot 2 [11052013]

Now problem 3 is where I split this vector in to 3 vectors ( months, Days, Years)

I want to be able to take Slot 1 and split its data. example I want to only take first 2 digits "0" "3" and put them into a vector called months.
same with other digits.
~> ( taking only (first 2), (3rd and 4th)and (last 4) digits)

Any one willing to give me any sort of help would be much appreciated.




Below this line I fixed.

-------------------- TL;DR---------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
	vector<string> appointment1;
	string line;
	//if (myfile.is_open())
	//{
	  while ( myfile.good() )
	  {
	  
		getline (myfile,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isdigit), 
		line.end());
		
	   line.erase( std::remove_if(line.begin(), line.end(), &ispunct), 
		line.end());
	  		appointment1.push_back(line);
	  }
	//}

	//else cout << "Can't open file\n"; 
	return appointment1;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
	vector<string> dates;
	string line;
	//if (myfile.is_open())
	//{
	  while ( myfile.good() )
	  {
	  
		getline (myfile,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isalpha), 
		line.end());
		
	   line.erase( std::remove_if(line.begin(), line.end(), &ispunct), 
		line.end());
	  		dates.push_back(line);
	  }
	//}

	//else cout << "Can't open file\n"; 
	return dates;
}


If this removes Digits and punctuations
What is the command to remove "NONE digits" ( words)??? is it isalpha ??

-----------------------------------------------------------------------------------
Thanks!












Ok so I want to make a program that takes an input file, reading each line of it and storing it in vector(s)(more than one vector i'll explain why shortyl)

Basically
this input file will contain appointments example
line 1 " 03/15/2019 josh turns eighteen"
line 2 " 11/05/2013 party in cplusplus forums"
etc...

Now I am really new to c++, so only method I came up with is to make 4 vectors( again I will explain shortly why)

Take this code for example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
	vector<string> v;
	string line;
	//if (myfile.is_open())
	//{
	  while ( myfile.good() )
	  {
		getline (myfile,line);
		v.push_back(line);
	  }
	//}

	//else cout << "Can't open file\n"; 
	return v;
}


This is how you store an input file into a vector.

What I want to do now is, make 4 vectors one stores appointment names("josh turns eighteen"), other 3 store Years("2019"), Months("03"), Days("15").



My problem doing this method is I lack knowledge in c++ ( I will explain here what I need help with)

Basically I want to know

Problem 1)
How do I ignore integers and "/" when I copy line to appointment string.
"" [b]03/15/2019
josh turns eighteen""
getline (myfile,line);[/b]

Problem 2)
Like problem one, except now I Want to ignore words and "/" "
" 03/15/2019 josh turns eighteen"

This time instead of string line would "int line;" ( automatically ignore "/" and words? or will I get some error?) if so how do I ignore words and punctuations?
getline (myfile,line);[/b]


Problem 3) ( taking only first 2, last 4, and 3rd,4th digits)

similar to problem 2, only now when I store the integers into a vector ( assuming I get help and fix problem 1 and 2) it would look like this

Vector dates slot 1 [03152019] slot 2 [11052013]

Now problem 3 is where I split this vector in to 3 vectors ( months, Days, Years)

I want to be able to take Slot 1 and split its data. example I want to only take first 2 digits "0" "3" and put them into a vector called months.
same with other digits.
~> ( taking only (first 2), (3rd and 4th)and (last 4) digits)

Any one willing to give me any sort of help would be much appreciated.

----------( not required to read below this line)-------------------------------

I have made a bubble sort that organizes appointments, where it shifts all slots of the 4 vectors based on which day comes first( if I move the day vector slot, it does same for the other 3 vectors) Reason for this is because I am making a calender GUI tat prints appointment based on year month and day.
Last edited on
Ok
ispunct removes punctuations.

How do I remove ints and words?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
	vector<string> appointment1;
	string line;
	//if (myfile.is_open())
	//{
	  while ( myfile.good() )
	  {
	  
		getline (myfile,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isdigit), 
		line.end());
		
	   line.erase( std::remove_if(line.begin(), line.end(), &ispunct), 
		line.end());
	  		appointment1.push_back(line);
	  }
	//}

	//else cout << "Can't open file\n"; 
	return appointment1;
}




my Problem 1

does this fix it?
Last edited on
Topic archived. No new replies allowed.