test prog in VS6

Hi,
What I have to inlude/declare to make this main work, I'm using VS6 (sorry I can't upgrade to anything else in our non-profit). I want to check this code I borrowed, but failed to compile it.
Appreciate your help, I'm bit new to cpp. None of this worked for me:
#include <iostream.h>
#include <string.h>

1
2
3
4
5
6
7
8
int tmain(int argc, _TCHAR* argv[])
 {
   char buffer[1024]
   std::cin.getline(buffer, 1024);
   std::cout << "buffer: " << buffer << std::endl;

   return 0;
 }


Tx
M
closed account (1vRz3TCk)
VS6 is very old (pre-standard), you will have to make a lot of changes to modern code to get it to work.
1
2
3
4
5
6
7
8
int tmain(int argc, _TCHAR* argv[])
 {
   char buffer[1024]  //missing semicolon here!
   std::cin.getline(buffer, 1024);
   std::cout << "buffer: " << buffer << std::endl;

   return 0;
 }


are you using C++/CLI not plain C++?
1
2
3
int main(int argc, char* argv[]) {
    return 0;
}
Last edited on
Tx, all

I'n not sure what I'm usihg C++ plain or not (sorry).
getting these errors no matter what I'm include

1
2
3
4
C:\t4\t4\t4.cpp(14) : error C2653: 'std' : is not a class or namespace name
C:\t4\t4\t4.cpp(14) : error C2065: 'cin' : undeclared identifier
C:\t4\t4\t4.cpp(14) : error C2228: left of '.getline' must have class/struct/union type
Error executing cl.exe.
Last edited on
In other word I see this my test pgm like below works fine, but I need to test how it handles input with '<' sigh,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h>
#include <string>
#include <fstream>
#include "iostream.h"
#include <string>
#include "stdlib.h"
#include "stdafx.h"


int main(int argc, char* argv[]) {
//	char buffer[1024];
//	std::cin.getline(buffer, 1024);
//	std::cout << "buffer: " << buffer << std::endl;
	printf("Hello World!\n");
    return 0;
}
You're using such an old compiler that it doesn't recognise modern standard C++.

Can you really not use one of the many modern free-of-charge compilers?
If you've got precompiled headers enabled for the compilation, stdafx.h must come first. The compiler ignores everything that come before it.

Also, why the duplicated file names? And the mixing of STL versions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "stdafx.h" // must come first!
#include <windows.h>
#include <string>
#include <fstream>
#include <iostream> // "iostream.h" is the older STL (with no std namespace)
//#include <string> duplicate
#include <cstdlib> // better than including <stdlib.h> directly
// and all standard header should be in <>
//#include "stdafx.h" moved

int main(int argc, char* argv[]) {
	char buffer[1024];
	std::cin.getline(buffer, 1024);
	std::cout << "buffer: " << buffer << std::endl;
	//printf("Hello World!\n");
    return 0;
}


vc6 is prob not a disaster if you're not into heavy templating. But we used StlPort in place of the STL provided by Microsoft (if was not up to spec in those days).

But, unless you need MFC, I would do as Mochops suggested, and switch to a nice, shiny, new modern version of Visual Studio or Code::Blocks or ...

Andy
PS @codekiddy - the _TCHAR is just a typedef of wchar_t -- when _UNICODE is #defined --
or char otherwise. Similarly, _tmain is a macro that evaluates to either wmain or main. See <tchar.h> for too much detail.
Last edited on
Tx, all much.
I have compile it like below to check instream intput from console, but nothing displayed, Is right how it should work or my code is wrong, I'm running it like test.exe < inp.txt .
And one more time i'm on VS6, don/t have any choice...

Tx
M
1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include <iostream>
using namespace std;

int main (int argc, char* argv[])  {
	char buffer[1024];
	cin.getline(buffer, 1024);
	cout << "buffer: " << buffer << endl;
    return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
//#include "stdafx.h"
#include <iostream>
using namespace std;

int main (int argc, char* argv[])  {
	char buffer[1024];
	cin.getline(buffer, 1024);
	cout << "buffer: " << buffer << endl;
	cin.get(); //<<< to prevent the console closes 
    return 0;
}

I´m using Code::Blocks 10.05
It all works now, tx again to all cpp'es
Topic archived. No new replies allowed.