Jump to content
  • Advertisement
Sign in to follow this  
Fixxer

fstream

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how come im getting these errors?
Compiling...
main.cpp
C:\Documents and Settings\Owner\Desktop\Lightning Round\CTA_Login_Server\main.cpp(97) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::al
locator<char> >' (or there is no acceptable conversion)
C:\Documents and Settings\Owner\Desktop\Lightning Round\CTA_Login_Server\main.cpp(98) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::al
locator<char> >' (or there is no acceptable conversion)
C:\Documents and Settings\Owner\Desktop\Lightning Round\CTA_Login_Server\main.cpp(99) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::al
locator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.

CTA_Login_Server.exe - 3 error(s), 0 warning(s)


with this code
ifstream a_file (cUsername);
			if (!a_file.is_open())
			{
				std::string error("B", 2);
				send(AcceptSocket, error.c_str(), error.size(),0);
				cout<<"Error Code "<< error.c_str() << " has been sent out."<<endl;
			}
			else
			{
				std::string fieldTwo;
				std::string access;
				std::string temp;
				a_file>>temp;    // LINE 97
				a_file>>fieldTwo;   // LINE 98
				a_file>>access;   //LINE 99


Share this post


Link to post
Share on other sites
Advertisement
yes I have included it.
Here is my entire source code.



/**********************************************************************
*
* main.cpp
* CTA_Login_Server
* (c)2005 Nathan Krygier. All Rights Reserved.
*
***********************************************************************/


#include <iostream.h>
#include <string>
#include <fstream.h>
#include <stdio.h>
#include <winsock2.h>

void main(){
cout<<"Call To Arms Login Server v1.00"<<endl;
cout<<"(c)2005 Nathan Krygier. All Rights Reserved."<<endl;
cout<<""<<endl;
cout<<"Attempting to start server."<<endl;

//////////////////////////////////////////////////////////////////////////
// Start up winsock
//////////////////////////
// This section of code starts up winsock.
//////////////////////////////////////////////////////////////////////////
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if(iResult != NO_ERROR){
cout<<"Error at WSAStartup."<<endl;
}
else{
cout<<"WSAStartup Completed."<<endl;
}
SOCKET m_socket;
m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(m_socket == INVALID_SOCKET){
cout<<"Error at socket."<<endl;
WSACleanup();
return;
}
else{
cout<<"Socket Completed."<<endl;
}
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr("127.0.0.1");
service.sin_port = htons(27000);
if(bind(m_socket,(SOCKADDR*) &service,sizeof(service)) == SOCKET_ERROR){
cout<<"Error at bind."<<endl;
closesocket(m_socket);
return;
}
else{
cout<<"Bind Completed."<<endl;
}
if(listen(m_socket,8) == SOCKET_ERROR){
cout<<"Error listening on socket."<<endl;
}
else{
cout<<"\nServer is now online."<<endl;
}
SOCKET AcceptSocket;

//////////////////////////////////////////////////////////////////////////
// Main Program Loop
//////////////////////////
// This is the main application loop.
//////////////////////////////////////////////////////////////////////////
while(1){
AcceptSocket = accept(m_socket,NULL,NULL);
if(AcceptSocket != SOCKET_ERROR){
cout<<"New Connection."<<endl;
}
int iBytesRecv = SOCKET_ERROR;
char cRecvbuf[64] = "";
iBytesRecv = recv(AcceptSocket,cRecvbuf,64,0);
if(iBytesRecv > 0){
char cUsername[21];
char cPassword[18];
strcpy(cUsername,cRecvbuf);
strcpy(cPassword,&cRecvbuf[strlen(cRecvbuf)+1]);
cout<<"Login Requested. Username:"<<cUsername<<" Password:"<<cPassword<<endl;
strcat(cUsername,".txt.");
cout<<cUsername<<endl;
ifstream a_file (cUsername);
if (!a_file.is_open())
{
std::string error("B", 2);
send(AcceptSocket, error.c_str(), error.size(),0);
cout<<"Error Code "<< error.c_str() << " has been sent out."<<endl;
}
else
{
std::string fieldTwo;
std::string access;
std::string temp;
a_file>>temp;
a_file>>fieldTwo;
a_file>>access;
if (access.empty())
{
std::string error("C", 2);
send(AcceptSocket,error.c_str(), error.size(),0);
cout<<"Error Code "<< error.c_str() << " has been sent out."<<endl;
}
else if(fieldTwo == cPassword)
{
std::string error("A", 2);
send(AcceptSocket,error.c_str(), error.size(),0);
cout<<"Error Code "<< error.c_str() << " has been sent out."<<endl;
}
else{
cout<<"Unknown Error"<<endl;
}
}

}
}
return;
}

Share this post


Link to post
Share on other sites
What I meant is that since you're using #include <fstream.h>, you should change it to #include <fstream>. <fstream.h> is the pre-standard version of the fstream library, which means it doesn't play nicely with a lot of things, including std::string.

Share this post


Link to post
Share on other sites
<iostream> not <iostream.h>, <fstream> not <fstream.h> and <cstdio> not <stdio.h>. Plus add the resulting namespace requirements.

Enigma

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!