I commented on the code what is my doubt.

I don´t know I can´t I simply use arq_linha_part >> parm; If I use that it returns me the error:

1>------ Build started: Project: Interface GaussSolve, Configuration: Debug Win32 ------
1>Compiling...
1>Interface GaussSolve.cpp
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(424) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(424) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(424) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\string(424) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1021) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1021) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1021) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1021) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1014) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1014) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1014) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1014) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1007) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1007) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1007) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1007) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1000) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1000) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1000) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1000) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(975) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(975) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(975) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(975) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(934) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(934) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(934) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(934) : see declaration of 'std::operator >>'
1>c:\users\fernando\documents\visual studio 2008\projects\interface gausssolve\interface gausssolve\interface gausssolve.cpp(38) : error C2676: binary '>>' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>Build log was saved at "file://c:\Users\Fernando\Documents\Visual Studio 2008\Projects\Interface GaussSolve\Interface GaussSolve\Debug\BuildLog.htm"
1>Interface GaussSolve - 29 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The code above is working fine, my doubt is how to improve it.

Instead of creating another string stream and do like the code above, that it´s working fine, what can I do?

I think that how it´s, is just too repetitive the code, isn´t it??

Can anyone help me to improve that part? thanks

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib> // For exit()

//using namespace std;

int main()
{
    std::ifstream arquivo("entrada.txt");

    if (!arquivo)
    {
        std::cout << "File not found\n\n";
        std::system("PAUSE");
        std::exit(EXIT_FAILURE);
    }
    else
    {
        std::cout << "Loading file...Please wait...\n\n";
    }

    std::string arquivo_linha, arq_linha_part;
	double parm;
	//char * cstr;

    while (getline(arquivo, arquivo_linha))
    {
        if (arquivo_linha[0] != '#')
        {
            std::istringstream token(arquivo_linha);

            while(std::getline(token, arq_linha_part, ':'))
			{	
				std::stringstream temp(arq_linha_part); //after using this temp variable it workded fine
				temp >> parm; //in this part if I use arq_linha_part >> parm it gives me an error. Why that?
                std::cout << arq_linha_part << std::endl;
				std::cout << parm << std::endl;
            }
        }
    }
std::system("PAUSE");
}

Recommended Answers

All 2 Replies

Let me get this straight.. the code you are currently posting (with the temp stringstream) is working, but if you write

arq_linha_part >> parm;

It gives you an error?
If so, then it should give you an error. The short answer is that std::string (the arq_linha_part variable) does not have a >> operator that takes double (the parm) as second argument.

So one of the ways to convert an std::string to a double is by using an std::stringstream like you have in the current code.

Also.. in future it is probably not necessary to paste all of the compiler errors, after the first error the compiler usually gets totally confused and will spit out many more errors that might not be errors anymore after you fix the first few errors.

Thanks Thelamb,

Sorry I only saw that the error was too long after posting it.

But thanks, I thought that there was a better way to do that conversion.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.