Kankles
08-24-2009, 09:46 PM
This is the code I've implemented. Very basic.
#include <iostream>
using namespace std;
int main(){
char myArray[50];
cout << "What is the password? ";
cin.getline( myArray, 50, '\n');
if( !strcmp( myArray, "password")){
strcat( myArray, " is correct! Access granted!\n");
} else {
strcpy( myArray, "Invalid password!\n");
}
cout << myArray;
system("pause");
}
The error I am getting is:
Compiling: C:\Users\Chris\Documents\Scripts\Strings.c
C:\Users\Chris\Documents\Scripts\Strings.c:1:20: iostream: No such file or directory
C:\Users\Chris\Documents\Scripts\Strings.c:3: error: syntax error before "namespace"
C:\Users\Chris\Documents\Scripts\Strings.c:3: warning: data definition has no type or storage class
C:\Users\Chris\Documents\Scripts\Strings.c: In function `main':
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: `cout' undeclared (first use in this function)
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: (Each undeclared identifier is reported only once
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: for each function it appears in.)
C:\Users\Chris\Documents\Scripts\Strings.c:11: error: `cin' undeclared (first use in this function)
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 1 warnings
another script i was having difficulty with was from the second tutorial..
#include <iostream>
using namespace std;
int main ()
char name[40]{
cout << "Hello! What is your name?\n";
cin >> name;
cout << "Welcome to my program " << name;
system("PAUSE");
return 0;
}
It returned the errors:
Compiling: C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected init-declarator before "char"
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected `,' or `;' before "char"
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings
#include <iostream>
using namespace std;
int main(){
char myArray[50];
cout << "What is the password? ";
cin.getline( myArray, 50, '\n');
if( !strcmp( myArray, "password")){
strcat( myArray, " is correct! Access granted!\n");
} else {
strcpy( myArray, "Invalid password!\n");
}
cout << myArray;
system("pause");
}
The error I am getting is:
Compiling: C:\Users\Chris\Documents\Scripts\Strings.c
C:\Users\Chris\Documents\Scripts\Strings.c:1:20: iostream: No such file or directory
C:\Users\Chris\Documents\Scripts\Strings.c:3: error: syntax error before "namespace"
C:\Users\Chris\Documents\Scripts\Strings.c:3: warning: data definition has no type or storage class
C:\Users\Chris\Documents\Scripts\Strings.c: In function `main':
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: `cout' undeclared (first use in this function)
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: (Each undeclared identifier is reported only once
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: for each function it appears in.)
C:\Users\Chris\Documents\Scripts\Strings.c:11: error: `cin' undeclared (first use in this function)
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 1 warnings
another script i was having difficulty with was from the second tutorial..
#include <iostream>
using namespace std;
int main ()
char name[40]{
cout << "Hello! What is your name?\n";
cin >> name;
cout << "Welcome to my program " << name;
system("PAUSE");
return 0;
}
It returned the errors:
Compiling: C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected init-declarator before "char"
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected `,' or `;' before "char"
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings