Hello everybody . I have a text file , I want to compare ip with in line text
This is file text
Code:
codeguru.com
c++.com
C#.com
google.com
c+++.com
And this is my code
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
string getip(string hostname)
{
//function get ip
}
void main ()
{
string string_main="http://abc-xyz.com/www/~av.123.456.789.000?url.aspx/etc";
int count=0;
string string_sub;
ifstream infile;
infile.open ("E:\\test.txt");
while(!infile.eof()) // To get you all the lines.
{
getline(infile,string_sub); // Saves the line in string_sub.
// cout<<string_sub<<"\n"; // Prints our string_sub.
if (!string_sub.empty())
{
string temp=getip(string_sub); // get ip of string_sub on the text line by line
size_t result = string_main.find( temp ); //check string_sub on the text file line by line, comparable to string_main
if( result != string::npos ) // if found
{
count+=1;
}
}
}
infile.close();
//cout<< count <<"\n";
if (count != 0)
{
cout << "Found\n";
}
else
{
cout << "Not found\n";
}
getch();
}
Can you see it , How to create function get ip above ?
Thank you .
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
You obviously don't have a stdafx.h. How did you create the project and what MSVC version do you use?
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
1. Don't use conio.h/stdio.h. use iostream, which is more C++ oriented.
2. You have created an empty project, therefore there is no "stdafx.h" file, while copy/pasting the code, you've picked this one too, hence your compiler is complaining that it cannot find this file.
3. You also need to link with "ws2_32.lib", otherwise you'll started getting linking errors once you are done with compiler errors.
Following is the code for your reference.
Code:
#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include <Windows.h>
#include <tchar.h>
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib") // Need to link with ws2_32.lib
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA data;
struct hostent *host;
int result;
DWORD error;
result = WSAStartup( MAKEWORD( 2, 2 ), &data );
if( result )
{
std::cout << "Error initializing sockets!" << std::endl;
return 1;
}
host = gethostbyname( "www.google.com" );
if( !host )
{
error = WSAGetLastError();
}
return 0;
}
1. Don't use conio.h/stdio.h. use iostream, which is more C++ oriented.
2. You have created an empty project, therefore there is no "stdafx.h" file, while copy/pasting the code, you've picked this one too, hence your compiler is complaining that it cannot find this file.
3. You also need to link with "ws2_32.lib", otherwise you'll started getting linking errors once you are done with compiler errors.
Following is the code for your reference.
Code:
#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include <Windows.h>
#include <tchar.h>
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib") // Need to link with ws2_32.lib
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA data;
struct hostent *host;
int result;
DWORD error;
result = WSAStartup( MAKEWORD( 2, 2 ), &data );
if( result )
{
std::cout << "Error initializing sockets!" << std::endl;
return 1;
}
host = gethostbyname( "www.google.com" );
if( !host )
{
error = WSAGetLastError();
}
return 0;
}
Hi Ejaz . i try it and i get many error . All of error in file "ws2def.h" 127 Error and 16 Warning
Your question was to resolve the errors, which are done. Please start separate thread for different problems (i.e. do no start multiple question in a single thread). Anyway, for this specific case, you need to do little more. Following code is for your reference.
Hi . thank for your help
if you do not mind can see through my code, you can modify it slightly so that IP can print out. I think my jaw getip missing anything. Urge you to check out . I think in GetIP function
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.