reading names

closed account (i8bjz8AR)
so i have to write a small text filter that filters through a file, b.list, and outputs each name (first and last) of each actor. The b.list file contains movies and these actors names. Can't figure out how to output only the names. Here is what i have so far. We can only use things like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

std::string s;
while(std::getline(std::cin, s))
  std::cout << s.size();


std::string s = "abc def";
std::size_t n = s.find(' '); // Find the index of the first ' '
std::string first = s.substr(0, n);
std::string second = s.substr(n + 1);

std::string s = "hello";
std::cout << s[0] << '\n'; // prints 'h'
s[0] = 'y';                // modify the first character
std::cout << s[0] << '\n'; // prints 'y'
std::cout << s << '\n';    // prints "yello" 


which is an example they gave us


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
int main()
{


    for(b.list = 0; b.list <= ){
        cout s[i]

    }

  std::size_t n = s.find(' '); // Find the index of the first ' '


  std::string s;
  while(std::getline(std::cin, s))
    std::cout << s;



  return 0;
}


and here is a list of the file we have to filter through with movies and actors names

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Andreotti, Eduardo	Maria Goretti (2003) (TV)  [Child]  <28>

Apolloff, Carl		Mot nya tider (1939)  [de Soto Maior]  <33>

Arnett, James E.	Mirror Image: What Do You See in the Mirror (2003) (V)  ['Dad' St. James]

Atanackovic, Dejan	Deca sveta (1965)

Azad, Zeeshan		Kicking Off (2015)  [Prison Footballer]
			.hack//Liminality Vol. 1: In the Case of Mai Minase (2002) (V)  (voice: English version)  [Masaya Makino]  <16>
			.hack//Liminality Vol. 4: Trismegistus (2003) (V)  (voice: English version)  [Masaya Makino]  <17>
			.hack//Osen kakudai vol. 1 (2002) (VG)  (voice: English version)  [Additional Voices]  <36>
			.hack//Shinshoku osen vol. 3 (2002) (VG)  (voice: English version)  [Additional Voices]  <47>
			.hack//Zettai houi vol. 4 (2003) (VG)  (voice: English version)  [Additional Voices]  <47>
			3 Ninjas: High Noon at Mega Mountain (1998)  [Carl]  <14>
			Aa! Megamisama! The Movie (2000)  (voice) (as Bo William)  [Additional Voices]
			Absolute Strangers (1991) (TV)  [Arnie]  <18>
It looks like (though I may be wrong) the file uses the tab character '\t' as a delimiter, after the actor's name. If that is so, you could read the whole line and use the first '\t' to identify the end of the name.

(or possibly use getline with a tab delimiter, then a 'normal' getline with a newline delimiter).
Last edited on
closed account (i8bjz8AR)
That makes sense to me but I have no idea how I would do it
Look at lines 8 and 9 of your first example (find and substr). Just needs adapting to use tab instead of space - assuming this does indeed fit the file format.
Topic archived. No new replies allowed.