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 2 3269
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;
}
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>. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sergio |
last post by:
Olá pessoal
Estou com um problema num relatório, quando mando imprimir ou
visualizar um determinado relatório com um subrelatório que tem varios
campos entre os quais quant, preço, total, fazendo...
|
by: StellaAzzurra |
last post by:
Salve,
premettendo che non sono un esperta di access, vi pongo il mio
problema.
Sto facendo una rubrica con access ed avrei la necessità di fare in
modo che
se ad esempio un mio clienti avesse 5...
|
by: juli |
last post by:
Good afternoon!
I have an error while trying to convert to DateTime ,here is the code
and the error:
ArrayList al = new ArrayList();
temp_str=Line.Split(' ');
al.Add(temp_str); //...
|
by: juli |
last post by:
I am trying to convert an object of a class which is derived from
collectionbase class.It's not working:
while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1)
{
al.Add(line);
}...
|
by: Juan |
last post by:
Hola Grupo!
Tengo el siguiente problema.
Quiero desarrollar una aplicación ASP.NET con Visual Studio.NET y resulta
que cuando quiero crear una me aparece el siguiente mensaje
...
|
by: |
last post by:
Ho notato che se lascio un text box vuoto ottengo un errore in fase
inserimento valori in una tabella (INSERT INTO)
string IDAzienda = CodiceIns.Text;
string Ragione = RagioneIns.Text;
...
|
by: teo_teo_teo |
last post by:
ciao,
in un campo "file" di un documento xml ho qualcosa del tipo
..\folder\file.pdf
ovviamente nn posso cambiare il modo in cui il folder e il file sono
visualizzti in quel tag perché il file...
|
by: Alessandro |
last post by:
Problema con le RE....
Ho questa stringa "3 HOURS, 22 MINUTES, and 28 SECONDS" e la devo
'dividere' nelle sue tre parti "3 HOURS", "22 MINUTES", "28 SECONDS".
La cosa mi viene molto con le...
|
by: Mizietto |
last post by:
Ciao a tutti, è la prima volta che scrivo su questo ng ma non riesco
ad uscire da questo problema.
Ho un'applicazione realizzata in vb.net framework 1.1 che NON
"scoppia" su Windows 2000...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |