May 18, 2013 at 7:12pm UTC
Basically I have a txt with names and usernames. I know that name+username = up to 20 characters. How do I tell compiler to recognize empty space between names as a symbol and store 2 words as one?
1 2 3 4 5
char name[20];
<...>
ifstream in ("a.txt" );
<...>
in >> play[i][j].name (empty symbol) reading futher >> ...
Last edited on May 18, 2013 at 7:14pm UTC
May 18, 2013 at 7:16pm UTC
If they are both are only words on same line, you can use getline.
May 18, 2013 at 7:18pm UTC
Yes, one casual line contains name+username and some numbers.
Can you be more specific?
May 18, 2013 at 7:29pm UTC
in.getline(play[i][j].name, 19)
This will store entire line (or first 19 symbols if line is longer) into variable
May 18, 2013 at 7:43pm UTC
That's what I get with it:
error: ambiguous overload for 'operator>>' in 'in >> in.std::basic_ifstream<char>::<anonymous>.std::basic_istream<_CharT, _Traits>::getline<char, std::char_traits<char> >(((char*)(&(*(play + ((sizetype)(((unsigned int)i) * 1400u))))[j].grupe::name)), 19)'|
1 2 3 4 5 6
for (i=0; i<grp; i++){
in >> n[i];
//cout << n[i] << endl;
for (j=0; j<n[i]; j++){
in >> in.getline(play[i][j].name, 19) >> play[i][j].mins >> play[i][j].sec;}}
}
I've tried also this approach:
1 2
in >> play[i][j].name >> temp >> play[i][j].mins >> play[i][j].sec;
play[i][j].name=play[i][j].name + " " + temp;
but then ironically I get
error: invalid operands of types 'char [20]' and 'const char [2]' to binary 'operator+'|
I guess it won't work this way with char[20].
Last edited on May 18, 2013 at 7:50pm UTC