#need help to fix that
52 messages · Page 1 of 1 (latest)
#include <iostream>
#iclude <string>
void printText(){
std::getline(std::cin, printText);
std::cout <<printText;
}
int main(){
printText();
}
something like that maybe?
#incude <iostream> then?
yes
yes, in main you mention printext instead of printText
oh nevermind
could you send the error message?
is this in C or in C++? because C++ needs a class, usualy you would use main as class and printext would become a method within that class
also getline buffer is incorrect
ur setting it as the function
it should be a char array instead
oh and i just noticed you used prinText for method name as well as the string name(wich you didn't initialize)
.
;compile
#include <iostream>
void prinText(){
char text[1024];
std::getline(std::cin, text);
std::cout << text << std::endl;
}
int main(){
prinText();
return 0;
}
<source>: In function 'void prinText()':
<source>:5:15: error: no matching function for call to 'getline(std::istream&, char [1024])'
5 | std::getline(std::cin, text);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/string:55,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ios:44,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ostream:40,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iostream:41,
from <source>:1:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.tcc:893:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(basic_is
its a function
not a name
;compile
#include <iostream>
#include <string>
void prinText(){
char text[1024];
std::getline(std::cin, text);
std::cout << text << std::endl;
}
int main(){
prinText();
return 0;
}
<source>: In function 'void prinText()':
<source>:5:15: error: no matching function for call to 'getline(std::istream&, char [1024])'
5 | std::getline(std::cin, text);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/string:55,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ios:44,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ostream:40,
from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iostream:41,
from <source>:1:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.tcc:893:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(basic_is
oh
nvm
it expects an input lmfao
try my code ive given u
it should work
the buffer is correct now
what is it
getline expects a buffer where the text is supposed to be written, ur input
he made text char array
@slate widget is there a reason to use char array in stead of string?
its the same
string just holds the char array and modifies it
according to ur needs
why?
??
can u just provide me the error
just copy paste the error lmao
or atleast take a screenshot
ah
so its a must to have a string obj
#include <iostream>
#include <string>
void prinText(){
std::string text;
std::getline(std::cin, text);
std::cout << text << std::endl;
}
int main(){
prinText();
return 0;
}
try now
read the error lmao
mismatched types
read it
no problem
u should read the docs tho
i m just a bit confused as to why it does not accept char arrays but string is fine