Hi,

I´m having problem while converting char to string.

#include "stdafx.h"
#include <fstream> 
#include <cstdio>
#include <iostream>


int main()
{
		std::ifstream arquivo("entrada.txt");
		if (!arquivo)
		{
			std::cout << "Arquivo não encontrado" << std::endl<< std::endl;
			system("PAUSE");
			exit(0);
		}
		
		std::string token;
		
		char arquivo_linha[255];

		while(arquivo)
		{
			arquivo.getline(arquivo_linha,255);
			if (arquivo_linha[0] != 35)
			{
			token = arquivo_linha;
		     	//std::cout << token << std::endl;
			printf("%s\n",token); 
			}
		}

		system("PAUSE");
	return 0;
}

This code only returns <null> on printf, but it works fine if I print the arquivo_linha.

I tried to use arquivo_linha.c_str() but it returns 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(35) : error C2228: left of '.c_str' must have class/struct/union
1> type is 'char [255]'
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 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thanks,

Fernando.

Sorry I forgot to include string ..

=// so idiot error...

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.