| View previous topic :: View next topic |
| Author |
Message |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 6:31 pm Post subject: [Help, C++] Error, strings |
|
|
Hey guys, I'm currently working on strings and I keep getting an error.
Here is my example code, im just using this so that i know what to do for further use for strings, i know this is just gonna print the string and it servers no purpose but i just needa know so i know what to do with other stuff
My code:
| Code: |
#include "iostream.h"
#include "stdlib.h"
#include "string.h"
int main
{
string mystring;
mystring == 'abcdef';
cout << mystring << endl;
return 0;
}
|
Error1: 'main' : looks like a function definition, but there is no parameter list; skipping apparent body
Error2: error C2015: too many characters in constant
for some reason the string in string mystring; doesn't highlight blue like when doing an int or char. is there another word for strings. also should i be declaring an int for main or is there something else, ty =]
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Jul 25, 2008 6:37 pm Post subject: |
|
|
1. Main is a function so you must put a () after it (ie. int main() )
2. single quote's mean character, while double quote's mean string.
3. == is a condition for equality, while = is for assignment.
edit:
4. #include <iostream> / #include <string>
5. std::string mystring; std::cout << ... or using namespace std (even tho its pointless for 2 things)
mystring = "abcdef";
should work.
_________________
Last edited by lurc on Fri Jul 25, 2008 6:40 pm; edited 3 times in total |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri Jul 25, 2008 6:38 pm Post subject: |
|
|
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 6:39 pm Post subject: |
|
|
@lurc I made those changes and i still get 1 error,
error C2470: 'main' : looks like a function definition, but there is no parameter list; skipping apparent body
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 6:40 pm Post subject: |
|
|
Try:
| Code: |
#include <iostream>
#include <string>
int main() {
std::string mystring = "abcdef";
std::cout<<mystring;
return 0;
}
|
Btw, find a new tutorial, yours is outdated.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Jul 25, 2008 6:40 pm Post subject: |
|
|
look at my edits.
and noz's.
_________________
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 6:42 pm Post subject: |
|
|
| Edit: i got it to work, thanks guys =]
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 6:43 pm Post subject: |
|
|
| oib111 wrote: | Try:
| Code: |
#include <iostream>
#include <string>
int main() {
std::string mystring = "abcdef";
std::cout<<mystring;
return 0;
}
|
Btw, find a new tutorial, yours is outdated. |
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 6:46 pm Post subject: |
|
|
| oib111 wrote: | | oib111 wrote: | Try:
| Code: |
#include <iostream>
#include <string>
int main() {
std::string mystring = "abcdef";
std::cout<<mystring;
return 0;
}
|
Btw, find a new tutorial, yours is outdated. |
|
I'm using C++ all in one desk reference for Dummies 7books in 1 edition . I hope i can still use it was printed in 2003 so it doesn't seem that old. Also the program keeps closing, can i use
thanks
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 6:49 pm Post subject: |
|
|
Well it uses bad methods such as including header files with "" instead of <> and using iostream.h and string.h (those are outdated). And try to avoid using system(""). Use this to pause:
| Code: |
std::cin.sync();
std::cin.get();
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 6:54 pm Post subject: |
|
|
| oib111 wrote: | Well it uses bad methods such as including header files with "" instead of <> and using iostream.h and string.h (those are outdated). And try to avoid using system(""). Use this to pause:
| Code: |
std::cin.sync();
std::cin.get();
|
|
Ok , 1. I HAVE to do #include "iostream.h" Im using Visual C++ 2008 and you have seperate file that has #include <iostream> in it and iostream.h is the file name. It's not that im using iostream.h <.<
Also, i used
cin.sync();
cin.get();
and works great, thanks
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 6:57 pm Post subject: |
|
|
Your welcome. But look, you don't have to use #include "iostream.h" in VC++ 2008. Just replace these lines of code:
| Code: |
#include "iostream.h"
#include "string.h"
|
with these lines of code:
| Code: |
#include <iostream>
#include <string>
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 7:04 pm Post subject: |
|
|
| oib111 wrote: | Your welcome. But look, you don't have to use #include "iostream.h" in VC++ 2008. Just replace these lines of code:
| Code: |
#include "iostream.h"
#include "string.h"
|
with these lines of code:
| Code: |
#include <iostream>
#include <string>
|
|
Tried before and doesn't work =O
When I make my new project it has 3 folders, headers, resource files, and source files.
in headers i have to make 3 header files with all the headers and i write it there as #include <iostream>
but when i got my main source file, i have to write with " " to tell it to include that header file, then it reads what to include. idk why but thats how i have to do it <.< If i don't, i get compiling errors.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 7:13 pm Post subject: |
|
|
Lol. You need to learn how to use VC++. Always create empty projects. Hit Ctrl+Shift+N. Go to Win32 section. Choose Console. Put in a name and hit next, hit next again. Then select "Empty Project" and hit next. Now right click on the Source folder and click Add New File. Choose a cpp file and name it whatever you want. Then put in:
| Code: |
#include <iostream>
#include <string>
int main() {
std::string mystring = "abcdef";
std::cout<<mystring;
std::cin.sync();
std::cin.get();
return 0;
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Fri Jul 25, 2008 7:25 pm Post subject: |
|
|
| oib111 wrote: | Lol. You need to learn how to use VC++. Always create empty projects. Hit Ctrl+Shift+N. Go to Win32 section. Choose Console. Put in a name and hit next, hit next again. Then select "Empty Project" and hit next. Now right click on the Source folder and click Add New File. Choose a cpp file and name it whatever you want. Then put in:
| Code: |
#include <iostream>
#include <string>
int main() {
std::string mystring = "abcdef";
std::cout<<mystring;
std::cin.sync();
std::cin.get();
return 0;
}
|
|
That's what i've done everytime. It doesn't matter to me as long as it does what it's suppost to <.<
|
|
| Back to top |
|
 |
|