By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Problema with string convertion and more...

P: n/a
Hi All
I'm in a nightmare trying to do a simple c++ program...

I want to read a file that will have strings in a vector. The path where
is the file is in a ini file.

I did:

--------------------
void main(void) {

// example of using the setINIFileName method
CIniReader m_IniReader;
CString m_strINIFile = ".\\javier.ini";
m_IniReader.setINIFileName (m_strINIFile);
CString pathPhones = m_IniReader.getKeyValue("pathPhones","main");

cout << "pathPhones es " << pathPhones;

std::vector<std::string> phones;

std::ifstream in(pathPhones + "phones.txt"); // Line 28

for (std::string line; std::getline(in, line); )
phones.push_back(line);
}

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

And I get error messages at compile time:

C:\Temp\PruebaIni\PruebaIni.cpp(28) : error C2079: 'in' uses undefined
class 'basic_ifstream<char,struct std::char_traits<char> >'
C:\Temp\PruebaIni\PruebaIni.cpp(28) : error C2440: 'initializing' :
cannot convert from 'class CString' to 'int'
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
C:\Temp\PruebaIni\PruebaIni.cpp(30) : error C2780: 'class
std::basic_istream<_E,_Tr> &__cdecl std::getline(class
std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const
_E)' : expects 3 arguments - 2 provided
c:\archivos de programa\microsoft visual
studio\vc98\include\string(149) : see declaration of 'getline'
C:\Temp\PruebaIni\PruebaIni.cpp(30) : error C2784: 'class
std::basic_istream<_E,_Tr> &__cdecl std::getline(class
std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' :
could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'int'
Error executing cl.exe.
Could somebody help me ?

Thanks in advance

J

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello, this code works, try it if you want:

#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
ifstream in_file("strings.dat");

if (!in_file) return 1;

vector<string> svec;
string tmp_s;

while (getline(in_file, tmp_s))
svec.push_back(tmp_s);

return 0;
}

Jul 23 '05 #2

P: n/a
Javier wrote:
Hi All
I'm in a nightmare trying to do a simple c++ program...

I want to read a file that will have strings in a vector. The path where
is the file is in a ini file.

I did:
No headers?
--------------------
void main(void) {
main must return int.
// example of using the setINIFileName method
CIniReader m_IniReader;
CString m_strINIFile = ".\\javier.ini";
m_IniReader.setINIFileName (m_strINIFile);
CString pathPhones = m_IniReader.getKeyValue("pathPhones","main");

cout << "pathPhones es " << pathPhones;

std::vector<std::string> phones;

std::ifstream in(pathPhones + "phones.txt"); // Line 28

for (std::string line; std::getline(in, line); )
phones.push_back(line);
}

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

And I get error messages at compile time:

C:\Temp\PruebaIni\PruebaIni.cpp(28) : error C2079: 'in' uses undefined
class 'basic_ifstream<char,struct std::char_traits<char> >'
Forgot to #include <fstream> maybe? It looks like the compiler knows a
declaration (from <iosfwd>?) but not the definition. Since you omitted all
your #include directives, it's hard to tell.
C:\Temp\PruebaIni\PruebaIni.cpp(28) : error C2440: 'initializing' :
cannot convert from 'class CString' to 'int'
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
Well, what is "CString"? Does it have an operator+ and a conversion operator
to const char*?
C:\Temp\PruebaIni\PruebaIni.cpp(30) : error C2780: 'class
std::basic_istream<_E,_Tr> &__cdecl std::getline(class
std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const
_E)' : expects 3 arguments - 2 provided
That looks strange. getline does have three parameters, but the third is
supposed to have a default value.
c:\archivos de programa\microsoft visual
studio\vc98\include\string(149) : see declaration of 'getline'
C:\Temp\PruebaIni\PruebaIni.cpp(30) : error C2784: 'class
std::basic_istream<_E,_Tr> &__cdecl std::getline(class
std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' :
could not deduce template argument for 'class std::basic_istream<_
E,_Tr> &' from 'int'


Again, it looks as if you forgot to #include <fstream>.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.