Problema with string convertion and more...

J

Javier

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
 
S

SnaiL

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;
}
 
R

Rolf Magnus

Javier said:
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?

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
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>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top