#1
Alright so I'm writing a silly little program that basically
Goes into a directory
Reads each individual directory
Goes into each individual subdirectory, and outputs all the contents, and then goes to the next subdir and so on...

So basically a bunch of dir commands
My main problem is, I'm using system("dir /B > file.txt");
to output the directory to a text file
Then I'd read the text file line by line, to get the subdirectory name to open
My problem is within reading the text file back into the program
The subdirectories can all have spaces in them, so I can't just simply use a
infile >> input; to catch it, 'cos it'll only catch one word
currently I'm using

std::getline(infile,artist);

infile being the the file I'm getting that data from, obviously, and artist being the name of the string that I'm putting the line into.
But I get an error whenever I try to use it, despite every website saying that's what I should use.

I also tried using

istream::getline(infile,artist);

But that didn't work either.

I get errors every time on compiling.

I know I should probably use character arrays with the getline, but if I do that there's another part of the program that I have to fight with, and I don't feel like it.

So, anyone have any ideas?


tl;dr: I need to get a line of text and getline(infile,artist); any ideas without using char arrays?
#3
Quote by CoreysMonster
std::getline(herpes,amy_winehouse);

I chuckled.
Banging on a trash can
Drumming on a street light
#5
Are you sure that that is the line that's failing, and not a missing semicolon or sorts from one of the lines above?
Electrics:ˑˑˑˑˑˑˑˑˑˑˑˑˑˑAmps:
Jackson DKMGFFˑˑˑˑˑˑˑˑˑˑRandall RG100SC G2
Washburn DIME 333ˑˑˑˑˑˑˑRandall RH200X / RA412 2x Half-Stacks
ESP LTD EC-1000 STCB
Dean From Hell CFH
#6
Quote by CoreysMonster
std::getline(herpes,amy_winehouse);



This should work btw

If it doesn't, www.cplusplus.com is your new friend.

I'll look more into it when I get back from work anyway
#7
Quote by SinnaSatan
Are you sure that that is the line that's failing, and not a missing semicolon or sorts from one of the lines above?



Yea, the error is quite specific


c:\users\joe\documents\visual studio 2008\projects\music list\music list\music list.cpp(38) : error C2784:
 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> 
&,std::basic_string<_Elem,_Traits,_Alloc> &' :
 could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:fstream'

1>        c:\program files\microsoft visual studio 9.0\vc\include\string(527) : see declaration of 'std::getline'


I broke it up a bit so it didn't ridiculously stretch the page.

Different errors depending on how I do it, but they're all close to that
Last edited by identityxcrysis at Jan 7, 2009,
#8
#include <iostream>
#include <string>
using namespace std;

Looking at the error code on MSDN, I think you should try adding that to the top of your cpp file.

The "using namespace std" means you don't have to put std:: before every operation that is in this namespace, which can save a lot of time.
#9
Quote by Freddedonna
#include <iostream>
#include <string>
using namespace std;

Looking at the error code on MSDN, I think you should try adding that to the top of your cpp file.

The "using namespace std" means you don't have to put std:: before every operation that is in this namespace, which can save a lot of time.



I've already got using namespace std;

I just wrote std:: to better clarify it, and showing the difference between std:: and istream::
#10
Quote by CoreysMonster
std::getline(herpes,amy_winehouse);


The solution to every programming problem.