Visual studio 2015 getline

Jan 30, 2016 at 6:26pm
Trying to write a parser and I keep getting stuck on this one part. I'm using visual studio 2015 and I swear either i'm stupid or visual studio is trolling me. I've included so many headers, I've tried writing it several ways
cin.getline()
getline()
std::getline(std::cin,x)

and i get the same errors

>c:\users\brian\desktop\hacking and programming\c++\testing\testing\source.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\brian\desktop\hacking and programming\c++\testing\testing\source.cpp(18): error C2664: 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::getline(_Elem *,std::streamsize,_Elem)': cannot convert argument 1 from 'std::istream' to 'char *'
1> with
1> [
1> _Elem=char
1> ]
1> c:\users\brian\desktop\hacking and programming\c++\testing\testing\source.cpp(18): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;

main()
{

	string user;

	char text_array[256];

	cout << "Hi there cherished user, please enter a mathematical formula :D\n";
	getline (cin, user,);


}


Thanks for taking time to read this and any advice would be appreciated
Jan 30, 2016 at 6:31pm
You have an extra comma in there.
Jan 30, 2016 at 6:32pm
Well.

main() Should be int main()

But the main problem is, first of all, you got a random coma operator after "user".

getline (cin, user,); // what is that random coma after user doing?

It should be

getline (cin, user);

Lastly, you havent included the string header.

#include <string>
Jan 30, 2016 at 6:35pm
I conflated #include cstring with #include string. *facepalm What is #include <cstring> anyway?

*fixed code below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
using namespace std;

int main()
{

	string user;

	char text_array[256];

	cout << "Hi there cherished user, please enter a mathematical formula :D\n";
	getline (cin, user);


}
Last edited on Jan 30, 2016 at 6:38pm
Jan 30, 2016 at 6:37pm
Lastly, you havent included the string header.
#include <string>
Jan 30, 2016 at 6:40pm
closed account (E0p9LyTq)
Thank you for using code tags!

You have several errors, each reported by VS 2015:

1. for STL string it is #include <string> , not #include <cstring> . <cstring> is for C library functions.

2. int main(), not main()

3. getline() takes 2 parameters. you have a comma after user so VS 2015 thinks you are supplying 3 parameters.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

int main()
{
   std::string aString;

   std::cout << "Enter a string: ";
   std::getline(std::cin, aString);

   std::cout << aString << "\n";
}


When given multiple errors it helps if you only look at them one at a time, fixing a single error. Many times fixing a single error fixes multiple errors.
Jan 30, 2016 at 6:43pm
Well thanks for the help everyone. One step closer to finishing this project. :D
Topic archived. No new replies allowed.